{"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":"exception","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/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimes.py#L353-L389","documentation":"Raised during DatetimeArray construction when tz is explicitly None (explicit_tz_none) but the values are detected as timezone-aware. Silently stripping a tz in this case would be a destructive implicit conversion, so pandas refuses and points at the intentional APIs (tz_localize/tz_convert).","triggerScenarios":"pd.DatetimeIndex(tz_aware_series, tz=None), pd.to_datetime(tz_aware_series).tz_localize(None) mis-wired, or constructing a Series/Index by passing tz-aware Timestamps while passing tz=None explicitly. Also pd.DatetimeIndex(..., tz=None) with tz-aware inputs.","commonSituations":"Trying to 'remove' a timezone by passing tz=None to the constructor instead of calling tz_localize(None). Refactoring that swapped tz_localize for a constructor kwarg. Dashboard code wanting 'naive UTC' display.","solutions":["Drop the tz intentionally via obj.tz_localize(None).","If you want naive UTC, first tz_convert('UTC') then tz_localize(None).","Stop passing tz=None explicitly when feeding tz-aware data; let the inferred tz stick or pass the matching tz."],"exampleFix":"# before\npd.DatetimeIndex(tz_aware_series, tz=None)\n\n# after\npd.DatetimeIndex(tz_aware_series).tz_localize(None)\n# or to anchor to UTC first:\ntz_aware_series.dt.tz_convert('UTC').dt.tz_localize(None)","handlingStrategy":"type-guard","validationCode":"if getattr(series.dtype, 'tz', None) is not None and tz is None:\n    raise ValueError('data is tz-aware; call .tz_localize(None) instead of tz=None')","typeGuard":"def is_tz_aware(s) -> bool:\n    d = getattr(s, 'dtype', None)\n    return isinstance(d, pd.DatetimeTZDtype) or getattr(d, 'tz', None) is not None","tryCatchPattern":"try:\n    pd.DatetimeIndex(data, tz=tz)\nexcept ValueError as e:\n    if 'incompatible with' in str(e) and 'tz=None' in str(e):\n        pd.DatetimeIndex(data).tz_localize(None)\n    else: raise","preventionTips":["Never pass tz=None to tz-aware data; use tz_localize(None).","Check series.dt.tz before constructing."],"tags":["datetime","timezone","constructor","validation"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}