{"record":{"id":"3b69c6ccb91bdca8","repo":"microsoft/qlib","slug":"when-sampling-minute-calendar-freq-of-raw-calenda","errorCode":null,"errorMessage":"when sampling minute calendar, freq of raw calendar must be minute or min","messagePattern":"when sampling minute calendar, freq of raw calendar must be minute or min","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/utils/resam.py","lineNumber":46,"sourceCode":"    region: str\n        Region, for example, \"cn\", \"us\"\n    Returns\n    -------\n    np.ndarray\n        The calendar with frequency freq_sam\n    \"\"\"\n    if region is None:\n        region = C[\"region\"]\n\n    freq_raw = Freq(freq_raw)\n    freq_sam = Freq(freq_sam)\n    if not len(calendar_raw):\n        return calendar_raw\n\n    # if freq_sam is xminute, divide each trading day into several bars evenly\n    if freq_sam.base == Freq.NORM_FREQ_MINUTE:\n        if freq_raw.base != Freq.NORM_FREQ_MINUTE:\n            raise ValueError(\"when sampling minute calendar, freq of raw calendar must be minute or min\")\n        else:\n            if freq_raw.count > freq_sam.count:\n                raise ValueError(\"raw freq must be higher than sampling freq\")\n        _calendar_minute = np.unique(list(map(lambda x: cal_sam_minute(x, freq_sam.count, region), calendar_raw)))\n        return _calendar_minute\n\n    # else, convert the raw calendar into day calendar, and divide the whole calendar into several bars evenly\n    else:\n        _calendar_day = np.unique(list(map(lambda x: pd.Timestamp(x.year, x.month, x.day, 0, 0, 0), calendar_raw)))\n        if freq_sam.base == Freq.NORM_FREQ_DAY:\n            return _calendar_day[:: freq_sam.count]\n\n        elif freq_sam.base == Freq.NORM_FREQ_WEEK:\n            _day_in_week = np.array(list(map(lambda x: x.dayofweek, _calendar_day)))\n            _calendar_week = _calendar_day[np.ediff1d(_day_in_week, to_begin=-1) < 0]\n            return _calendar_week[:: freq_sam.count]\n\n        elif freq_sam.base == Freq.NORM_FREQ_MONTH:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/utils/resam.py#L28-L64","documentation":"Error \"when sampling minute calendar, freq of raw calendar must be minute or min\" thrown in microsoft/qlib.","triggerScenarios":"This error is raised at qlib/utils/resam.py:46 when the guard condition fails: \"when sampling minute calendar, freq of raw calendar must be minute or min\". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.","commonSituations":"See trigger scenarios.","solutions":["Use a raw calendar with minute ('min') frequency when sampling a minute-level calendar.","Resample from daily data instead if no minute-level raw calendar is available."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}