pandas-dev/pandas · error · ValueError

left and right must have the same time zone, got '{left.tz}'

Error message

left and right must have the same time zone, got '{left.tz}' and '{right.tz}'

What it means

Raised when both bounds are timezone-aware DatetimeIndex objects but their time zones differ. IntervalArray requires a single consistent tz for both endpoints. Fires at pandas/core/arrays/interval.py:343.

Source

Thrown at pandas/core/arrays/interval.py:343

            isinstance(left.dtype, CategoricalDtype)
            or is_string_dtype(left.dtype)
            or is_string_dtype(right.dtype)
        ):
            # GH 19016, GH 66518: reject unsupported right-side dtypes too.
            msg = (
                "category, object, and string subtypes are not supported "
                "for IntervalArray"
            )
            raise TypeError(msg)
        if isinstance(left, ABCPeriodIndex):
            msg = "Period dtypes are not supported, use a PeriodIndex instead"
            raise ValueError(msg)
        if isinstance(left, ABCDatetimeIndex) and str(left.tz) != str(right.tz):
            msg = (
                "left and right must have the same time zone, got "
                f"'{left.tz}' and '{right.tz}'"
            )
            raise ValueError(msg)
        elif needs_i8_conversion(left.dtype) and left.unit != right.unit:
            # e.g. m8[s] vs m8[ms], try to cast to a common dtype GH#55714
            left_arr, right_arr = left._data._ensure_matching_resos(right._data)
            left = ensure_index(left_arr)
            right = ensure_index(right_arr)

        # For dt64/td64 we want DatetimeArray/TimedeltaArray instead of ndarray
        left = ensure_wrapped_if_datetimelike(left)
        left = extract_array(left, extract_numpy=True)
        right = ensure_wrapped_if_datetimelike(right)
        right = extract_array(right, extract_numpy=True)

        if isinstance(left, ArrowExtensionArray) or isinstance(
            right, ArrowExtensionArray
        ):
            pass
        else:
            lbase = getattr(left, "_ndarray", left)

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Localize both to a common tz: `left = left.tz_convert('UTC')`, `right = right.tz_convert('UTC')`.
  2. If one side is tz-naive, localize it first: `left.tz_localize('UTC')`.
  3. Strip tz from both if wall-clock equality is intended: `left.tz_localize(None)`.

Example fix

// before
pd.IntervalIndex.from_arrays(df['start_utc'], df['end_local'])
// after
pd.IntervalIndex.from_arrays(df['start_utc'].dt.tz_convert('UTC'), df['end_local'].dt.tz_convert('UTC'))
Defensive patterns

Strategy: validation

Validate before calling

import pandas as pd

def align_tz(left, right, target='UTC'):
    if getattr(left, 'tz', None) is None:
        left = left.tz_localize(target)
    else:
        left = left.tz_convert(target)
    if getattr(right, 'tz', None) is None:
        right = right.tz_localize(target)
    else:
        right = right.tz_convert(target)
    return left, right

Type guard

def same_tz(left, right) -> bool:
    return str(getattr(left, 'tz', None)) == str(getattr(right, 'tz', None))

Try / catch

try:
    ia = pd.IntervalArray(left, right)
except ValueError as e:
    if "same time zone" in str(e):
        ia = pd.IntervalArray(left.tz_convert('UTC'), right.tz_convert('UTC'))
    else:
        raise

Prevention

When it happens

Trigger: `pd.IntervalIndex.from_arrays(ts_utc, ts_us)`, or constructing from columns sourced from joins of differently-tz-aware datetime data.

Common situations: Merging datasets where one side is stored UTC and the other in a local tz; reading parquet/csv that applies different tz inference per column.

Related errors


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