{"record":{"id":"7c32a1b9b3b37322","repo":"pandas-dev/pandas","slug":"start-and-end-cannot-both-be-tz-aware-with-differe","errorCode":null,"errorMessage":"Start and end cannot both be tz-aware with different timezones","messagePattern":"Start and end cannot both be tz-aware with different timezones","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":3087,"sourceCode":"    Parameters\n    ----------\n    start : Timestamp\n    end : Timestamp\n    tz : tzinfo or None\n\n    Returns\n    -------\n    tz : tzinfo or None\n\n    Raises\n    ------\n    TypeError : if start and end timezones do not agree\n    \"\"\"\n    try:\n        inferred_tz = timezones.infer_tzinfo(start, end)\n    except AssertionError as err:\n        # infer_tzinfo raises AssertionError if passed mismatched timezones\n        raise TypeError(\n            \"Start and end cannot both be tz-aware with different timezones\"\n        ) from err\n\n    inferred_tz = timezones.maybe_get_tz(inferred_tz)\n    tz = timezones.maybe_get_tz(tz)\n\n    if tz is not None and inferred_tz is not None:\n        if not timezones.tz_compare(inferred_tz, tz):\n            raise AssertionError(\"Inferred time zone not equal to passed time zone\")\n\n    elif inferred_tz is not None:\n        tz = inferred_tz\n\n    return tz\n\n\ndef _maybe_normalize_endpoints(\n    start: _TimestampNoneT1, end: _TimestampNoneT2, normalize: bool","sourceCodeStart":3069,"sourceCodeEnd":3105,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/datetimes.py#L3069-L3105","documentation":"Raised by _infer_tz_from_endpoints (used by date_range and similar generators) when both `start` and `end` are tz-aware but their tzinfos disagree. The function calls timezones.infer_tzinfo which raises an AssertionError on mismatch; that is caught and re-raised as a TypeError with this message. The function's Raises contract documents this behavior.","triggerScenarios":"Calling `pd.date_range(start=pd.Timestamp('2020-01-01', tz='US/Eastern'), end=pd.Timestamp('2020-01-02', tz='UTC'))`. Any API that internally calls _infer_tz_from_endpoints with mismatched-aware endpoints.","commonSituations":"Building endpoints from different sources (one from a DB in UTC, one user-supplied in local tz). Hardcoded start tz vs. dynamic end tz. Misconfigured tz on one side of a date window.","solutions":["Align both endpoints to the same tz before calling date_range: `end = end.tz_convert(start.tz)`.","Drop tz from both sides if you want a tz-naive range.","Construct the range in UTC and convert the result: `pd.date_range(..., tz='UTC').tz_convert(target)`."],"exampleFix":"// before\nrng = pd.date_range(start=ts_est, end=ts_utc)\n\n// after\nrng = pd.date_range(start=ts_est, end=ts_utc.tz_convert(ts_est.tz))","handlingStrategy":"validation","validationCode":"import pandas as pd\n\ndef aligned_endpoints(start, end):\n    stz = getattr(start, 'tzinfo', None) if start is not None else None\n    etz = getattr(end, 'tzinfo', None) if end is not None else None\n    if stz is not None and etz is not None and stz != etz:\n        end = end.tz_convert(stz)\n    return start, end","typeGuard":"def endpoints_tz_compatible(start, end) -> bool:\n    stz = getattr(start, 'tzinfo', None) if start is not None else None\n    etz = getattr(end, 'tzinfo', None) if end is not None else None\n    return stz is None or etz is None or stz == etz","tryCatchPattern":"try:\n    rng = pd.date_range(start=start, end=end)\nexcept TypeError as e:\n    if 'different timezones' in str(e):\n        end = end.tz_convert(start.tz)\n        rng = pd.date_range(start=start, end=end)\n    else:\n        raise","preventionTips":["Normalize all date_range endpoints to one tz at ingest.","Use UTC throughout internally; convert only at presentation."],"tags":["datetime","timezone","date-range","construction"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}