{"record":{"id":"6886a8ac4bcde4b3","repo":"pandas-dev/pandas","slug":"how-with-perioddtype-is-no-longer-supported-u","errorCode":null,"errorMessage":"'{how}' with PeriodDtype is no longer supported. Use (obj != pd.Period(0, freq)).{how}() instead.","messagePattern":"'(.+?)' with PeriodDtype is no longer supported\\. Use \\(obj != pd\\.Period\\(0, freq\\)\\)\\.(.+?)\\(\\) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/datetimelike.py","lineNumber":1638,"sourceCode":"        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\n        # All of the functions implemented here are ordinal, so we can\n        #  operate on the tz-naive equivalents\n        npvalues = self._ndarray.view(\"M8[ns]\")\n\n        from pandas.core.groupby.ops import WrappedCythonOp\n\n        kind = WrappedCythonOp.get_kind_from_how(how)\n        op = WrappedCythonOp(how=how, kind=kind, has_dropped_na=has_dropped_na)\n\n        res_values = op._cython_op_ndim_compat(\n            npvalues,","sourceCodeStart":1620,"sourceCodeEnd":1656,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/datetimelike.py#L1620-L1656","documentation":"Raised by _groupby_op when grouping a PeriodDtype column with how in {'any','all'}. Mirrors error 257 for Period dtypes: the implicit truthiness comparison was removed (GH#34479) and the user must materialise the boolean mask explicitly via comparison against pd.Period(0, freq).","triggerScenarios":"df.groupby(key)[period_col].any() or .all(); reached via the branch at line 1636-1641.","commonSituations":"Post-upgrade behavior change; generic 'reduce every column' code paths; mixing boolean reductions across heterogeneous dtypes.","solutions":["Materialise the mask first: (df['p'] != pd.Period(0, df['p'].dt.freq)).groupby(df['key']).any().","Test for non-NaT instead: df['p'].notna().groupby(df['key']).all().","Drop the Period column from any/all aggregations.","Pin pandas version if you depend on the legacy implicit truthiness, while planning migration."],"exampleFix":"// before\ndf.groupby('key')['period_col'].any()  # TypeError: 'any' with PeriodDtype no longer supported\n// after\n(df['period_col'].notna()).groupby(df['key']).any()","handlingStrategy":"type-guard","validationCode":"from pandas.api.types import is_period_dtype\nif is_period_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_period_dtype\n    return is_period_dtype(col.dtype) and how in {'any','all'}","tryCatchPattern":"try:\n    out = df.groupby('key')['p'].any()\nexcept TypeError as e:\n    if 'no longer supported' in str(e) and 'PeriodDtype' in str(e):\n        out = df['p'].notna().groupby(df['key']).any()\n    else:\n        raise","preventionTips":["Replace Period any/all with explicit boolean masks (col.notna()).","Audit aggregation pipelines after pandas upgrades.","Drop Period columns from any/all reductions."],"tags":["groupby","any","all","period","deprecated"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}