{"record":{"id":"89a72eec81780f07","repo":"pandas-dev/pandas","slug":"how-with-datetime64-dtypes-is-no-longer-suppor","errorCode":null,"errorMessage":"'{how}' with datetime64 dtypes is no longer supported. Use (obj != pd.Timestamp(0)).{how}() instead.","messagePattern":"'(.+?)' with datetime64 dtypes is no longer supported\\. Use \\(obj != pd\\.Timestamp\\(0\\)\\)\\.(.+?)\\(\\) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimelike.py","lineNumber":1627,"sourceCode":"\n    def _groupby_op(\n        self,\n        *,\n        how: str,\n        has_dropped_na: bool,\n        min_count: int,\n        ngroups: int,\n        ids: npt.NDArray[np.intp],\n        **kwargs,\n    ):\n        dtype = self.dtype\n        if dtype.kind == \"M\":\n            # Adding/multiplying datetimes is not valid\n            if how in [\"sum\", \"prod\", \"cumsum\", \"cumprod\", \"var\", \"skew\", \"kurt\"]:\n                raise TypeError(f\"datetime64 type does not support operation '{how}'\")\n            if how in [\"any\", \"all\"]:\n                # GH#34479\n                raise TypeError(\n                    f\"'{how}' with datetime64 dtypes is no longer supported. \"\n                    f\"Use (obj != pd.Timestamp(0)).{how}() instead.\"\n                )\n\n        elif isinstance(dtype, PeriodDtype):\n            # Adding/multiplying Periods is not valid\n            if how in [\"sum\", \"prod\", \"cumsum\", \"cumprod\", \"var\", \"skew\", \"kurt\"]:\n                raise TypeError(f\"Period type does not support {how} operations\")\n            if how in [\"any\", \"all\"]:\n                # GH#34479\n                raise TypeError(\n                    f\"'{how}' with PeriodDtype is no longer supported. \"\n                    f\"Use (obj != pd.Period(0, freq)).{how}() instead.\"\n                )\n        # timedeltas we can add but not multiply\n        elif how in [\"prod\", \"cumprod\", \"skew\", \"kurt\", \"var\"]:\n            raise TypeError(f\"timedelta64 type does not support {how} operations\")\n","sourceCodeStart":1609,"sourceCodeEnd":1645,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimelike.py#L1609-L1645","documentation":"Raised by _groupby_op when grouping a datetime64 column with how in {'any','all'}. Since GH#34479 these boolean reductions on datetime64 are no longer supported because the implicit 'datetime != 0' comparison was confusing; the message tells you to compute the boolean mask explicitly.","triggerScenarios":"df.groupby(key)[ts_col].any() or .all() on a datetime64 column; reached via the branch at line 1625-1630.","commonSituations":"Behavioral change upgrading across pandas versions that dropped implicit datetime truthiness; generic 'aggregate everything' code that runs any/all over all columns.","solutions":["Materialize the boolean mask first: (df['ts'] != pd.Timestamp(0)).groupby(key).any().","Or test for non-NaT directly: df['ts'].notna().groupby(key).all().","Drop the datetime column from any/all aggregations.","Pin the pandas version if you rely on legacy behavior, and schedule a migration."],"exampleFix":"// before\ndf.groupby('key')['timestamp'].any()  # TypeError: 'any' with datetime64 no longer supported\n// after\n(df['timestamp'].notna()).groupby(df['key']).any()","handlingStrategy":"type-guard","validationCode":"from pandas.api.types import is_datetime64_any_dtype\nif is_datetime64_any_dtype(col.dtype) and how in {'any','all'}:\n    series = col.notna()\nelse:\n    series = col\nout = series.groupby(df['key']).agg(how)","typeGuard":"def needs_explicit_mask(col, how: str) -> bool:\n    from pandas.api.types import is_datetime64_any_dtype\n    return is_datetime64_any_dtype(col.dtype) and how in {'any','all'}","tryCatchPattern":"try:\n    out = df.groupby('key')['ts'].any()\nexcept TypeError as e:\n    if 'no longer supported' in str(e) and 'datetime64' in str(e):\n        out = df['ts'].notna().groupby(df['key']).any()\n    else:\n        raise","preventionTips":["Replace datetime any/all with explicit boolean masks (col.notna() or col != Timestamp(0)).","Audit aggregation pipelines after pandas upgrades.","Drop datetime columns from any/all reductions."],"tags":["groupby","any","all","datetime","deprecated"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}