Skip to content

BUG: Series.round() expects ExtensionArray.round() to be implemented #49387

@andrewgsavage

Description

@andrewgsavage

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • 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 #26730

Expected Behavior

A note in EA docs to implement round if that's needed.

Installed Versions

INSTALLED VERSIONS

commit : 91111fd
python : 3.10.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 151 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 1.5.1
numpy : 1.23.3
pytz : 2022.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.2.2
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.4.0
pandas_datareader: None
bs4 : None
bottleneck : 1.3.5
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.2
numba : None
numexpr : 2.8.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugExtensionArrayExtending pandas with custom dtypes or arrays.ExtensionArray - New Method RequestSuggestion to add a new method to the EA base class/interface.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions