{"record":{"id":"2db79f9402531d8d","repo":"pandas-dev/pandas","slug":"data-is-already-tz-aware-inferred-tz-unable-to","errorCode":null,"errorMessage":"data is already tz-aware {inferred_tz}, unable to set specified tz: {tz}","messagePattern":"data is already tz-aware (.+?), unable to set specified tz: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":2948,"sourceCode":"    Parameters\n    ----------\n    tz : tzinfo or None\n    inferred_tz : tzinfo or None\n\n    Returns\n    -------\n    tz : tzinfo or None\n\n    Raises\n    ------\n    TypeError : if both timezones are present but do not match\n    \"\"\"\n    if tz is None:\n        tz = inferred_tz\n    elif inferred_tz is None:\n        pass\n    elif not timezones.tz_compare(tz, inferred_tz):\n        raise TypeError(\n            f\"data is already tz-aware {inferred_tz}, unable to set specified tz: {tz}\"\n        )\n    return tz\n\n\ndef _validate_dt64_dtype(dtype):\n    \"\"\"\n    Check that a dtype, if passed, represents either a numpy datetime64[ns]\n    dtype or a pandas DatetimeTZDtype.\n\n    Parameters\n    ----------\n    dtype : object\n\n    Returns\n    -------\n    dtype : None, numpy.dtype, or DatetimeTZDtype\n","sourceCodeStart":2930,"sourceCodeEnd":2966,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L2930-L2966","documentation":"Raised by _maybe_infer_tz when the data already implies a tz (inferred_tz) and the caller passed a different tz. Pandas will not silently re-stamp data that already has a clear tz; the inferred and requested tz must match. TypeError.","triggerScenarios":"Constructing a DatetimeIndex/Series from tz-aware Timestamps while also passing tz='Other/Zone' that differs; pd.to_datetime(aware_list, tz=other_tz).","commonSituations":"Data is already in one tz (e.g. Europe/London) but code forces tz='UTC'; mismatched tz between source data and a hardcoded tz kwarg.","solutions":["Drop the explicit tz= argument and let pandas infer from the data.","If you need a different tz, tz_convert the result instead of passing a conflicting tz=.","Pre-normalize the input data to the desired tz before construction."],"exampleFix":"# before\npd.DatetimeIndex([pd.Timestamp('2020', tz='UTC')], tz='US/Eastern')\n# after\npd.DatetimeIndex([pd.Timestamp('2020', tz='UTC')]).tz_convert('US/Eastern')","handlingStrategy":"validation","validationCode":"def build_index(ts_list, tz=None):\n    inferred = None\n    for t in ts_list:\n        t = pd.Timestamp(t)\n        if t.tzinfo is not None:\n            inferred = t.tzinfo\n            break\n    if tz is not None and inferred is not None and str(tz) != str(inferred):\n        raise TypeError(f'tz conflict: data={inferred} requested={tz}')\n    return pd.DatetimeIndex(ts_list, tz=tz)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't pass tz= when data already carries a tz.","tz_convert after construction to change zones.","Pre-normalize inputs to one tz."],"tags":["datetime","timezone","construction","pandas"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}