Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
andrewgsavage opened this issue Oct 29, 2022 · 2 comments · May be fixed by #54582
Open
3 tasks done

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

andrewgsavage opened this issue Oct 29, 2022 · 2 comments · May be fixed by #54582
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.

Comments

@andrewgsavage
Copy link

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

@andrewgsavage andrewgsavage added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 29, 2022
@codestorm177
Copy link

codestorm177 commented Nov 6, 2022

Thank you for giving a detailed description. Looking into this now

@topper-123 topper-123 added ExtensionArray Extending pandas with custom dtypes or arrays. and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 10, 2023
@topper-123
Copy link
Contributor

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.

@andrewgsavage andrewgsavage linked a pull request Aug 16, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants