pandas-dev/pandas · error · ValueError
Inferred frequency {inferred} from passed values does not co
Error message
Inferred frequency {inferred} from passed values does not conform to passed frequency {freq.freqstr} What it means
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.
Source
Thrown at pandas/core/arrays/datetimelike.py:1867
end=None,
periods=len(index),
freq=freq,
unit=index.unit,
**kwargs,
)
if not lib.array_equivalent_bytes(index.asi8, on_freq.asi8):
raise ValueError
except ValueError as err:
if "non-fixed" in str(err):
# non-fixed frequencies are not meaningful for timedelta64;
# we retain that error message
raise err
# GH#11587 the main way this is reached is if the `np.array_equal`
# check above is False. This can also be reached if index[0]
# is `NaT`, in which case the call to `cls._generate_range` will
# raise a ValueError, which we re-raise with a more targeted
# message.
raise ValueError(
f"Inferred frequency {inferred} from passed values "
f"does not conform to passed frequency {freq.freqstr}"
) from err
@classmethod
def _generate_range(
cls, start, end, periods: int | None, freq, *args, **kwargs
) -> Self:
raise AbstractMethodError(cls)
# --------------------------------------------------------------
@cache_readonly
def _creso(self) -> int:
return get_unit_from_dtype(self._ndarray.dtype)
@cache_readonly
def unit(self) -> TimeUnit:View on GitHub (pinned to 71959b8cb9)
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.
Example fix
# before (irregular spacing conflicts with claimed freq)
idx = pd.DatetimeIndex(['2020-01-01','2020-01-03'], freq='D')
# after
idx = pd.DatetimeIndex(['2020-01-01','2020-01-03']) # freq inferred as None
# or regenerate a conforming index
idx = pd.date_range('2020-01-01', periods=2, freq='2D') Defensive patterns
Strategy: validation
Validate before calling
inferred = pd.infer_freq(values)
if inferred is not None and freq is not None and inferred != freq:
raise ValueError(f'inferred {inferred} != requested {freq}') Try / catch
try:
pd.DatetimeIndex(values, freq=freq)
except ValueError as e:
if 'does not conform to passed frequency' in str(e):
pd.DatetimeIndex(values) # drop the conflicting freq
else: raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Passed data is timezone-aware, incompatible with 'tz=None'.
- Must provide freq argument if no data is supplied
- Must specify a valid frequency: {freq}
- {freq=} is not supported
- value should be a '{self._scalar_type.__name__}' or 'NaT'. G
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/99d17d98c0f951de.
Report an issue: GitHub.