{"record":{"id":"0da474184b190a9c","repo":"pandas-dev/pandas","slug":"to-pydatetime-cannot-be-called-with-self-dtype-py","errorCode":null,"errorMessage":"to_pydatetime cannot be called with {self.dtype.pyarrow_dtype} type. Convert to pyarrow timestamp type.","messagePattern":"to_pydatetime cannot be called with (.+?) type\\. Convert to pyarrow timestamp type\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":4270,"sourceCode":"        return self._round_temporally(\"round\", freq, ambiguous, nonexistent)\n\n    def _dt_day_name(self, locale: str | None = None) -> Self:\n        if locale is None:\n            locale = \"C\"\n        result = pc.strftime(self._pa_array, format=\"%A\", locale=locale)\n        return self._from_pyarrow_array(result)\n\n    def _dt_month_name(self, locale: str | None = None) -> Self:\n        if locale is None:\n            locale = \"C\"\n        result = pc.strftime(self._pa_array, format=\"%B\", locale=locale)\n        return self._from_pyarrow_array(result)\n\n    def _dt_to_pydatetime(self) -> Series:\n        from pandas import Series\n\n        if pa.types.is_date(self.dtype.pyarrow_dtype):\n            raise ValueError(\n                f\"to_pydatetime cannot be called with {self.dtype.pyarrow_dtype} type. \"\n                \"Convert to pyarrow timestamp type.\"\n            )\n        data = self._pa_array.to_pylist()\n        if self._dtype.pyarrow_dtype.unit == \"ns\":\n            data = [None if ts is None else ts.to_pydatetime(warn=False) for ts in data]\n        return Series(data, dtype=object)\n\n    def _dt_tz_localize(\n        self,\n        tz,\n        ambiguous: TimeAmbiguous = \"raise\",\n        nonexistent: TimeNonexistent = \"raise\",\n    ) -> Self:\n        if ambiguous != \"raise\":\n            raise NotImplementedError(f\"{ambiguous=} is not supported\")\n        nonexistent_pa = {\n            \"raise\": \"raise\",","sourceCodeStart":4252,"sourceCodeEnd":4288,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L4252-L4288","documentation":"Raised by ArrowExtensionArray._dt_to_pydatetime when the array dtype is a pyarrow date type (date32/date64). `to_pydatetime` must return Python datetime objects, but date-typed pyarrow scalars are `datetime.date`, not `datetime.datetime`, so pandas refuses rather than silently returning the wrong type.","triggerScenarios":"Calling `ser.dt.to_pydatetime()` on a Series whose dtype is `date32[pyarrow]` or `date64[pyarrow]`.","commonSituations":"Reading a Parquet/Arrow column that was typed as a logical date and assuming `.dt.to_pydatetime()` works the same as on a timestamp column.","solutions":["Cast the column to a pyarrow timestamp first: `ser.astype('timestamp[ns][pyarrow]').dt.to_pydatetime()`.","If you actually want date objects, access them via `ser.to_numpy()` / `.dropna().tolist()` instead of to_pydatetime."],"exampleFix":"# before\ndate_series.dt.to_pydatetime()\n# after\ndate_series.astype('timestamp[ns][pyarrow]').dt.to_pydatetime()","handlingStrategy":"validation","validationCode":"import pyarrow as pa\nif pa.types.is_date(ser.dtype.pyarrow_dtype):\n    raise ValueError(\"to_pydatetime needs a timestamp; cast first\")\nser.dt.to_pydatetime()","typeGuard":"def is_arrow_timestamp(ser) -> bool:\n    import pyarrow as pa\n    return pa.types.is_timestamp(getattr(ser.dtype, \"pyarrow_dtype\", None))","tryCatchPattern":"try:\n    out = ser.dt.to_pydatetime()\nexcept ValueError as e:\n    if \"to_pydatetime cannot be called\" in str(e):\n        out = ser.astype('timestamp[ns][pyarrow]').dt.to_pydatetime()\n    else:\n        raise","preventionTips":["Cast date columns to timestamp before to_pydatetime","Check pyarrow_dtype with pa.types.is_date to pick the right accessor"],"tags":["pyarrow","datetime-accessor","date","arrow-extension"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}