{"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":1636,"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(ordinal=0, freq=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":1618,"sourceCodeEnd":1654,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/datetimelike.py#L1618-L1654","documentation":"Raised in _groupby_op (GH#34479) when dtype.kind == 'M' and `how` is 'any' or 'all'. Earlier pandas versions allowed these to implicitly coerce datetimes to truthiness; that behavior was removed because it was ambiguous, so the operation now raises and directs users to an explicit (obj != pd.Timestamp(0)).any()/all().","triggerScenarios":"df.groupby('k')[date_col].any(); .all() on a datetime64 column; groupby aggregations listing 'any'/'all' across heterogeneous columns including datetime.","commonSituations":"Upgrading pandas across the version that removed implicit datetime truthiness (GH#34479); generic 'is there any data' checks that call .any() on every column.","solutions":["Make truthiness explicit: (df[date_col].notna()).any() or df.groupby('k')[date_col].apply(lambda s: s.notna().any()).","Use the suggested form (obj != pd.Timestamp(0)).any()/all() if you need a non-zero reference.","Run any/all on the notna mask of the datetime column rather than the column itself."],"exampleFix":"// before\ndf.groupby('k')['timestamp'].any()  # TypeError after GH#34479\n\n// after\ndf.assign(_has_ts=df['timestamp'].notna()).groupby('k')['_has_ts'].any()","handlingStrategy":"validation","validationCode":"import pandas as pd\n\nDT_TRUTH_OPS = {'any', 'all'}\n\ndef any_all_dt_safe(df, key, col, how):\n    if df[col].dtype.kind == 'M' and how in DT_TRUTH_OPS:\n        mask = df[col].notna()\n        return getattr(df.assign(_m=mask).groupby(key)['_m'], how)()\n    return getattr(df.groupby(key)[col], how)()","typeGuard":"import pandas as pd\n\ndef is_datetime64_series(s) -> bool:\n    return getattr(s, 'dtype', None) is not None and s.dtype.kind == 'M'","tryCatchPattern":"try:\n    return getattr(df.groupby('k')[date_col], how)()\nexcept TypeError as e:\n    if 'no longer supported' in str(e) and how in ('any', 'all'):\n        mask = df[date_col].notna()\n        return getattr(df.assign(_m=mask).groupby('k')['_m'], how)()\n    raise","preventionTips":["Use .notna().any()/.all() for existence checks on datetime columns.","Pin pandas version expectations when migrating across GH#34479.","Audit generic .any()/.all() pipelines for datetime64 columns."],"tags":["datetime","groupby","any","all","version-change","type-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}