Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import pint
import pint_pandas
s = pd.Series([1.2345678, 2.3456789])
s.round(2)
df_pint = pd.DataFrame([1.2345678, 2.3456789], dtype='pint[m]')
df_pint.round(2)
s_pint = pd.Series([1.2345678, 2.3456789], dtype='pint[m]')
s_pint.round(2) # this errors
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [19], in <cell line: 13>()
9 df_pint.round(2)
12 s_pint = pd.Series([1.2345678, 2.3456789], dtype='pint[m]')
---> 13 s_pint.round(2)
File ~\anaconda3\envs\pint-pandas-oct22\lib\site-packages\pandas\core\series.py:2602, in Series.round(self, decimals, *args, **kwargs)
2570 """
2571 Round each value in a Series to the given number of decimals.
2572
(...)
2599 dtype: float64
2600 """
2601 nv.validate_round(args, kwargs)
-> 2602 result = self._values.round(decimals)
2603 result = self._constructor(result, index=self.index).__finalize__(
2604 self, method="round"
2605 )
2607 return result
AttributeError: 'PintArray' object has no attribute 'round'
Issue Description
Series.round() expects ExtensionArray.round() to be implemented. ExtensionArray.round() isn't mentioned in any docs, so I'm suprised to see this error. Should EAs implement a round method?
Some previous discussion here, but with a different error message https://github.com/pandas-dev/pandas/issues/26730
Expected Behavior
A note in EA docs to implement round if that's needed.
Installed Versions
Comment From: codestorm177
Thank you for giving a detailed description. Looking into this now
Comment From: topper-123
ExtensionArray
can hold data that don't require a round
method, I don't think this is an issue with ExtensionArray
itself.
Probably there should be an abstract round
method in ExtensionOpsMixin
.