{"record":{"id":"603519693106c30e","repo":"pandas-dev/pandas","slug":"passed-data-is-timezone-aware-incompatible-with","errorCode":null,"errorMessage":"Passed data is timezone-aware, incompatible with 'tz=None'. Use obj.tz_localize(None) instead.","messagePattern":"Passed data is timezone-aware, incompatible with 'tz=None'\\. Use obj\\.tz_localize\\(None\\) instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimes.py","lineNumber":371,"sourceCode":"            unit = dtl.dtype_to_unit(dtype)\n\n        data, copy = dtl.ensure_arraylike_for_datetimelike(\n            data, copy, cls_name=\"DatetimeArray\"\n        )\n\n        subarr, tz = _sequence_to_dt64(\n            data,\n            copy=copy,\n            tz=tz,\n            dayfirst=dayfirst,\n            yearfirst=yearfirst,\n            ambiguous=ambiguous,\n            out_unit=unit,\n        )\n        # We have to call this again after possibly inferring a tz above\n        _validate_tz_from_dtype(dtype, tz, explicit_tz_none)\n        if tz is not None and explicit_tz_none:\n            raise ValueError(\n                \"Passed data is timezone-aware, incompatible with 'tz=None'. \"\n                \"Use obj.tz_localize(None) instead.\"\n            )\n\n        data_unit = np.datetime_data(subarr.dtype)[0]\n        data_unit = cast(\"TimeUnit\", data_unit)\n        data_dtype = tz_to_dtype(tz, data_unit)\n        result = cls._simple_new(subarr, dtype=data_dtype)\n        if unit is not None and unit != result.unit:\n            # If unit was specified in user-passed dtype, cast to it here\n            # error: Argument 1 to \"as_unit\" of \"TimelikeOps\" has\n            # incompatible type \"str\"; expected \"Literal['s', 'ms', 'us', 'ns']\"\n            # [arg-type]\n            result = result.as_unit(unit)  # type: ignore[arg-type]\n\n        return result\n\n    @classmethod","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/datetimes.py#L353-L389","documentation":"Raised by DatetimeArray._sequence_to_dt64 path when the supplied data is timezone-aware (a tz was inferred or present) but the caller explicitly requested tz=None. tz=None is ambiguous here — it could mean 'drop tz' or 'no tz expected' — so pandas makes the user choose with tz_localize(None), avoiding silent data loss.","triggerScenarios":"pd.DatetimeIndex(tz_aware_series, tz=None); pd.to_datetime(tz_aware_values, tz=None) is not the trigger here, but internal/array construction with explicit_tz_none=True against tz-aware data is; constructing Series/Index where the dtype or call signature forces tz=None.","commonSituations":"Passing an already-localized column into a constructor that defaults tz to None; refactoring code that previously used the old silent-drop behavior; mixing tz-aware sources in a pipeline that explicitly nulls tz.","solutions":["Drop the timezone intentionally: obj.tz_localize(None) before construction.","Preserve the timezone by passing the correct tz= explicitly.","If you want naive UTC values, obj.tz_convert('UTC').tz_localize(None)."],"exampleFix":"// before\naware = pd.Series(pd.to_datetime(['2020-01-01']).tz_localize('UTC'))\npd.DatetimeIndex(aware, tz=None)  # ValueError: tz-aware incompatible with tz=None\n\n// after\npd.DatetimeIndex(aware).tz_localize(None)  # explicitly drop tz","handlingStrategy":"validation","validationCode":"def build_index(values, tz=None):\n    inferred_tz = getattr(values.dtype, \"tz\", None)\n    if inferred_tz is not None and tz is None:\n        raise ValueError(\"data is tz-aware; call tz_localize(None) to drop\")\n    return pd.DatetimeIndex(values, tz=tz)","typeGuard":"def is_tz_aware(values) -> bool:\n    return getattr(getattr(values, \"dtype\", None), \"tz\", None) is not None","tryCatchPattern":"try:\n    idx = pd.DatetimeIndex(aware, tz=None)\nexcept ValueError as e:\n    if \"tz=None\" in str(e):\n        idx = pd.DatetimeIndex(aware).tz_localize(None)\n    else:\n        raise","preventionTips":["Never pass tz=None against tz-aware data; pass the explicit tz or call tz_localize.","Track tz state through your pipeline explicitly rather than defaulting to None.","Unit-test the tz-aware code path."],"tags":["pandas","datetime","timezone","tz-localize","validation"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}