{"record":{"id":"428f2704098dde16","repo":"microsoft/qlib","slug":"calendar-does-not-exist-self-calendar-path","errorCode":null,"errorMessage":"calendar does not exist: {self.calendar_path}","messagePattern":"calendar does not exist: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scripts/data_collector/future_calendar_collector.py","lineNumber":45,"sourceCode":"            qlib data directory\n        start_date\n            start date\n        end_date\n            end date\n        \"\"\"\n        self.qlib_dir = Path(qlib_dir).expanduser().absolute()\n        self.calendar_path = self.qlib_dir.joinpath(\"calendars/day.txt\")\n        self.future_path = self.qlib_dir.joinpath(\"calendars/day_future.txt\")\n        self._calendar_list = self.calendar_list\n        _latest_date = self._calendar_list[-1]\n        self.start_date = _latest_date if start_date is None else pd.Timestamp(start_date)\n        self.end_date = _latest_date + pd.Timedelta(days=365 * 2) if end_date is None else pd.Timestamp(end_date)\n\n    @property\n    def calendar_list(self) -> List[pd.Timestamp]:\n        # load old calendar\n        if not self.calendar_path.exists():\n            raise ValueError(f\"calendar does not exist: {self.calendar_path}\")\n        calendar_df = pd.read_csv(self.calendar_path, header=None)\n        calendar_df.columns = [\"date\"]\n        calendar_df[\"date\"] = pd.to_datetime(calendar_df[\"date\"])\n        return calendar_df[\"date\"].to_list()\n\n    def _format_datetime(self, datetime_d: [str, pd.Timestamp]):\n        datetime_d = pd.Timestamp(datetime_d)\n        return datetime_d.strftime(self.calendar_format)\n\n    def write_calendar(self, calendar: Iterable):\n        calendars_list = [self._format_datetime(x) for x in sorted(set(self.calendar_list + calendar))]\n        np.savetxt(self.future_path, calendars_list, fmt=\"%s\", encoding=\"utf-8\")\n\n    @abc.abstractmethod\n    def collector(self) -> Iterable[pd.Timestamp]:\n        \"\"\"\n\n        Returns","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/scripts/data_collector/future_calendar_collector.py#L27-L63","documentation":"Raised by CollectorFutureCalendar.calendar_list (scripts/data_collector/future_calendar_collector.py:45) when <qlib_dir>/calendars/day.txt does not exist. The future-calendar collector works by merging new exchange trading dates into the existing day calendar, so a pre-existing qlib data directory with a valid calendars/day.txt is a hard prerequisite. Its absence means the qlib_dir argument does not point at an initialized qlib data directory.","triggerScenarios":"Running `python future_calendar_collector.py collect --qlib_dir <dir> --region cn` where <dir> lacks calendars/day.txt — e.g. a fresh/empty directory, a typo in the path, or pointing at the qlib source tree instead of the data directory (~/.qlib/qlib_data/cn_data).","commonSituations":"First-time users who have not yet run `dump_bin.py`/downloaded cn_data before trying to extend the calendar; passing a relative path that resolves differently from the script's cwd (the code does Path(...).expanduser().absolute(), not resolve()); moving/renaming a data directory.","solutions":["Point --qlib_dir at an existing qlib data directory containing calendars/day.txt (default ~/.qlib/qlib_data/cn_data).","If no data dir exists yet, first download or bootstrap one (get_data.py or scripts/dump_bin.py) so calendars/day.txt is created.","Verify with: ls <qlib_dir>/calendars/day.txt before running the collector."],"exampleFix":"# before\nrun(qlib_dir='./cn_data', region='cn')  # empty dir, no calendars/day.txt\n\n# after\nimport os\nassert os.path.exists(os.path.expanduser('~/.qlib/qlib_data/cn_data/calendars/day.txt')), 'run dump_bin first'\nrun(qlib_dir='~/.qlib/qlib_data/cn_data', region='cn')","handlingStrategy":"validation","validationCode":"from pathlib import Path\nqlib_dir = Path(qlib_dir).expanduser()\nif not (qlib_dir / 'calendars' / 'day.txt').exists():\n    raise SystemExit(f'{qlib_dir} is not an initialized qlib data dir (calendars/day.txt missing); run dump_bin or download data first')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on one absolute qlib data path (e.g. ~/.qlib/qlib_data/cn_data) in all collector invocations.","BootStrap the data directory (get_data/dump_bin) before any calendar-extension tooling."],"tags":["calendar","qlib-dir","filesystem","future-calendar"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}