{"record":{"id":"99d17d98c0f951de","repo":"pandas-dev/pandas","slug":"inferred-frequency-inferred-from-passed-values-d","errorCode":null,"errorMessage":"Inferred frequency {inferred} from passed values does not conform to passed frequency {freq.freqstr}","messagePattern":"Inferred frequency (.+?) from passed values does not conform to passed frequency (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimelike.py","lineNumber":1867,"sourceCode":"                end=None,\n                periods=len(index),\n                freq=freq,\n                unit=index.unit,\n                **kwargs,\n            )\n            if not lib.array_equivalent_bytes(index.asi8, on_freq.asi8):\n                raise ValueError\n        except ValueError as err:\n            if \"non-fixed\" in str(err):\n                # non-fixed frequencies are not meaningful for timedelta64;\n                #  we retain that error message\n                raise err\n            # GH#11587 the main way this is reached is if the `np.array_equal`\n            #  check above is False.  This can also be reached if index[0]\n            #  is `NaT`, in which case the call to `cls._generate_range` will\n            #  raise a ValueError, which we re-raise with a more targeted\n            #  message.\n            raise ValueError(\n                f\"Inferred frequency {inferred} from passed values \"\n                f\"does not conform to passed frequency {freq.freqstr}\"\n            ) from err\n\n    @classmethod\n    def _generate_range(\n        cls, start, end, periods: int | None, freq, *args, **kwargs\n    ) -> Self:\n        raise AbstractMethodError(cls)\n\n    # --------------------------------------------------------------\n\n    @cache_readonly\n    def _creso(self) -> int:\n        return get_unit_from_dtype(self._ndarray.dtype)\n\n    @cache_readonly\n    def unit(self) -> TimeUnit:","sourceCodeStart":1849,"sourceCodeEnd":1885,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimelike.py#L1849-L1885","documentation":"Raised by DatetimeLikeArrayMixin._validate_frequency when both a frequency and raw values are supplied to the constructor and the frequency inferred from the values disagrees with the explicitly passed one. Internally it regenerates the range from the inferred start with the passed freq and compares asi8 bytes; a mismatch means the supplied freq is inconsistent with the spacing of the data.","triggerScenarios":"pd.DatetimeIndex(values, freq='...') or pd.date_range(...) where the data spacing does not match freq; constructing an index from a Series whose inferred stride differs from the freq keyword; reindexing/setting freq on irregular data; passing freq while loading data with gaps or a DST transition.","commonSituations":"Loading CSVs with missing timestamps, business-day data being labeled 'D', weekend gaps, DST fall-back producing a non-uniform stride, or stale freq metadata from a config that no longer matches the source data.","solutions":["Omit the freq argument and let pandas infer it, then .infer_freq() to inspect.","If the data is genuinely irregular, leave freq=None and do not assert a frequency.","If you intended a regular index, regenerate it with pd.date_range(start, periods, freq) and reattach your values.","Drop or forward-fill missing timestamps so the data actually conforms to the desired freq before assigning it."],"exampleFix":"# before (irregular spacing conflicts with claimed freq)\nidx = pd.DatetimeIndex(['2020-01-01','2020-01-03'], freq='D')\n\n# after\nidx = pd.DatetimeIndex(['2020-01-01','2020-01-03'])  # freq inferred as None\n# or regenerate a conforming index\nidx = pd.date_range('2020-01-01', periods=2, freq='2D')","handlingStrategy":"validation","validationCode":"inferred = pd.infer_freq(values)\nif inferred is not None and freq is not None and inferred != freq:\n    raise ValueError(f'inferred {inferred} != requested {freq}')","typeGuard":null,"tryCatchPattern":"try:\n    pd.DatetimeIndex(values, freq=freq)\nexcept ValueError as e:\n    if 'does not conform to passed frequency' in str(e):\n        pd.DatetimeIndex(values)  # drop the conflicting freq\n    else: raise","preventionTips":["Let pandas infer freq rather than asserting one when data may be irregular.","Validate source data for gaps/DST before assigning business-day or daily frequencies.","Log pd.infer_freq() output during ingestion to catch drift early."],"tags":["datetime","frequency","constructor","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}