pandas-dev/pandas · error · TypeError

data is already tz-aware {inferred_tz}, unable to set specif

Error message

data is already tz-aware {inferred_tz}, unable to set specified tz: {tz}

What it means

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.

Source

Thrown at pandas/core/arrays/datetimes.py:2948

    Parameters
    ----------
    tz : tzinfo or None
    inferred_tz : tzinfo or None

    Returns
    -------
    tz : tzinfo or None

    Raises
    ------
    TypeError : if both timezones are present but do not match
    """
    if tz is None:
        tz = inferred_tz
    elif inferred_tz is None:
        pass
    elif not timezones.tz_compare(tz, inferred_tz):
        raise TypeError(
            f"data is already tz-aware {inferred_tz}, unable to set specified tz: {tz}"
        )
    return tz


def _validate_dt64_dtype(dtype):
    """
    Check that a dtype, if passed, represents either a numpy datetime64[ns]
    dtype or a pandas DatetimeTZDtype.

    Parameters
    ----------
    dtype : object

    Returns
    -------
    dtype : None, numpy.dtype, or DatetimeTZDtype

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Drop the explicit tz= argument and let pandas infer from the data.
  2. If you need a different tz, tz_convert the result instead of passing a conflicting tz=.
  3. Pre-normalize the input data to the desired tz before construction.

Example fix

# before
pd.DatetimeIndex([pd.Timestamp('2020', tz='UTC')], tz='US/Eastern')
# after
pd.DatetimeIndex([pd.Timestamp('2020', tz='UTC')]).tz_convert('US/Eastern')
Defensive patterns

Strategy: validation

Validate before calling

def build_index(ts_list, tz=None):
    inferred = None
    for t in ts_list:
        t = pd.Timestamp(t)
        if t.tzinfo is not None:
            inferred = t.tzinfo
            break
    if tz is not None and inferred is not None and str(tz) != str(inferred):
        raise TypeError(f'tz conflict: data={inferred} requested={tz}')
    return pd.DatetimeIndex(ts_list, tz=tz)

Prevention

When it happens

Trigger: Constructing a DatetimeIndex/Series from tz-aware Timestamps while also passing tz='Other/Zone' that differs; pd.to_datetime(aware_list, tz=other_tz).

Common situations: 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.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/2db79f9402531d8d. Report an issue: GitHub.