{"record":{"id":"3422698b39db0d85","repo":"pandas-dev/pandas","slug":"cannot-round-dtype-self-dtype-as-it-is-non-numer","errorCode":null,"errorMessage":"Cannot round dtype {self.dtype} as it is non-numeric","messagePattern":"Cannot round dtype (.+?) as it is non-numeric","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/base.py","lineNumber":2945,"sourceCode":"        Series.round : Round values of a Series.\n\n        Notes\n        -----\n        This is a non-performant default implementation.  Subclasses are\n        encouraged to override it to avoid the elementwise loop.\n\n        Examples\n        --------\n        >>> arr = pd.array([1.234, 5.678, pd.NA], dtype=\"Float64\")\n        >>> arr.round(1)\n        <FloatingArray>\n        [1.2, 5.7, <NA>]\n        Length: 3, dtype: Float64\n        \"\"\"\n        if self.dtype._is_boolean:\n            return self.copy()\n        if not self.dtype._is_numeric:\n            raise TypeError(f\"Cannot round dtype {self.dtype} as it is non-numeric\")\n        # Python's builtin round on complex emits DeprecationWarning (and\n        # raises TypeError in a future Python release); use np.round there.\n        round_fn = np.round if self.dtype.kind == \"c\" else round\n        rounded = [\n            round_fn(item, decimals) if not item_isna else item\n            for item, item_isna in zip(self, self.isna(), strict=True)\n        ]\n        return type(self)._from_sequence(rounded, dtype=self.dtype)\n\n    def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):\n        if any(\n            isinstance(other, (ABCSeries, ABCIndex, ABCDataFrame)) for other in inputs\n        ):\n            return NotImplemented\n\n        result = arraylike.maybe_dispatch_ufunc_to_dunder_op(\n            self, ufunc, method, *inputs, **kwargs\n        )","sourceCodeStart":2927,"sourceCodeEnd":2963,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/base.py#L2927-L2963","documentation":"round() is only defined for numeric dtypes (and boolean, which is passed through unchanged as a fast path via self.dtype._is_boolean). For any other ExtensionArray dtype, self.dtype._is_numeric is False and round raises TypeError rather than silently no-op'ing, so callers learn the operation is meaningless. The implementation then uses round for real/integer kinds and np.round for complex.","triggerScenarios":"Calling Series.round / DataFrame.round / arr.round(n) on an ExtensionArray whose dtype is neither numeric nor boolean (e.g. string, categorical, a custom non-numeric EA).","commonSituations":"Applying df.round(2) to a frame containing string or categorical EA columns. Rounding a custom datetime-like or object EA. A pipeline that rounds the whole frame without selecting numeric columns.","solutions":["Restrict rounding to numeric columns: df.select_dtypes(include='number').round(n), or round named numeric columns only.","If you own a custom numeric-like EA, ensure self.dtype._is_numeric returns True so round proceeds.","Skip non-numeric columns before rounding in mixed-dtype frames."],"exampleFix":"// before\ndf.round(2)  # TypeError: Cannot round dtype string as it is non-numeric\n\n// after\ndf[['a','b']] = df[['a','b']].round(2)  # only numeric columns","handlingStrategy":"validation","validationCode":"if not (arr.dtype._is_numeric or arr.dtype._is_boolean):\n    raise TypeError(f'cannot round dtype {arr.dtype}')\nout = arr.round(n)","typeGuard":"def is_roundable_dtype(dtype) -> bool:\n    return bool(getattr(dtype, '_is_numeric', False)) or bool(getattr(dtype, '_is_boolean', False))","tryCatchPattern":"try:\n    out = series.round(2)\nexcept TypeError:\n    out = series  # non-numeric; leave unchanged","preventionTips":["Round only numeric columns: df.select_dtypes(include='number').round(n).","For custom numeric-like EAs, ensure dtype._is_numeric returns True.","Skip boolean/string/categorical columns before rounding."],"tags":["extension-array","type-error","rounding","pandas"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}