{"record":{"id":"98723d3e3711ddbb","repo":"pandas-dev/pandas","slug":"cumprod-not-supported-for-timedelta","errorCode":null,"errorMessage":"cumprod not supported for Timedelta.","messagePattern":"cumprod not supported for Timedelta\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/timedeltas.py","lineNumber":444,"sourceCode":"            (), {\"dtype\": dtype, \"out\": out, \"keepdims\": keepdims}, fname=\"std\"\n        )\n\n        result = nanops.nanstd(self._ndarray, axis=axis, skipna=skipna, ddof=ddof)\n        if axis is None or self.ndim == 1:\n            return self._box_func(result)\n        return self._from_backing_data(result)\n\n    # ----------------------------------------------------------------\n    # Accumulations\n\n    def _accumulate(self, name: str, *, skipna: bool = True, **kwargs):\n        if name == \"cumsum\":\n            op = getattr(datetimelike_accumulations, name)\n            result = op(self._ndarray.copy(), skipna=skipna, **kwargs)\n\n            return type(self)._simple_new(result, dtype=self.dtype)\n        elif name == \"cumprod\":\n            raise TypeError(\"cumprod not supported for Timedelta.\")\n\n        else:\n            return super()._accumulate(name, skipna=skipna, **kwargs)\n\n    # ----------------------------------------------------------------\n    # Rendering Methods\n\n    def _formatter(self, boxed: bool = False):\n        from pandas.io.formats.format import get_format_timedelta64\n\n        return get_format_timedelta64(self, box=True)\n\n    def _format_native_types(\n        self, *, na_rep: str | float = \"NaT\", date_format=None, **kwargs\n    ) -> npt.NDArray[np.object_]:\n        from pandas.io.formats.format import get_format_timedelta64\n\n        # Relies on TimeDelta._repr_base","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/timedeltas.py#L426-L462","documentation":"TimedeltaArray._accumulate raises TypeError for cumprod because cumulative product of time deltas is undefined (multiplying durations is not meaningful). cumsum is supported; cummin and cummax are inherited; cumprod is explicitly refused.","triggerScenarios":"s.cumprod() on a timedelta-dtype Series; df.cumprod() on a timedelta column; arr._accumulate('cumprod').","commonSituations":"Generic accumulation suites applied across mixed dtypes; refactoring a numeric column to timedelta and forgetting cumprod breaks.","solutions":["Drop cumprod from operations applied to timedelta columns.","If the values represent integers-as-durations, extract the numeric component first (.dt.total_seconds()) then cumprod.","Use cumsum if the goal was cumulative addition of durations."],"exampleFix":"// before\ns = pd.Series(pd.to_timedelta(['1 day','2 days']))\ns.cumprod()  # TypeError\n// after\ns.dt.total_seconds().cumprod()","handlingStrategy":"type-guard","validationCode":"def safe_cumprod(s):\n    if pd.api.types.is_timedelta64_dtype(s):\n        raise TypeError('cumprod not supported for timedelta')\n    return s.cumprod()","typeGuard":"def cumprod_safe_dtype(series) -> bool:\n    return pd.api.types.is_numeric_dtype(series)","tryCatchPattern":"try:\n    s.cumprod()\nexcept TypeError as e:\n    if 'cumprod not supported for Timedelta' in str(e):\n        s.dt.total_seconds().cumprod()\n    else:\n        raise","preventionTips":["Exclude timedelta columns from cumprod.","Extract numeric component (.dt.total_seconds()) if multiplication is required.","Use cumsum for cumulative addition of durations."],"tags":["pandas","timedelta","accumulation","cumprod","dtype"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}