Skip to content

pd.Series.round does not work when pd.Series contains PintArray #144

Open
@MichaelTiemannOSC

Description

@MichaelTiemannOSC

It is convenient to use pd.Series.round, but not with PintArrays. Here is a testcase:

import pandas as pd
import pint
import pint_pandas

aa = pd.Series([1.2345678, 2.3456789])
print(aa)
print(aa.round(2))

bb = pd.Series([1.2345678, 2.3456789], dtype='pint[m]')
print(bb)
print(bb.round(2))

Here is the program output (with a UnitStripped warning message removed):

0    1.234568
1    2.345679
dtype: float64
0    1.23
1    2.35
dtype: float64

0    1.2345678
1    2.3456789
dtype: pint[meter]
Traceback (most recent call last):
  File "/Users/michael/Documents/GitHub/ITR-MichaelTiemannOSC/examples/pint-round.py", line 11, in <module>
    print(bb.round(2))
  File "/Users/michael/Documents/GitHub/pandas/pandas/core/series.py", line 2602, in round
    result = self._values.round(decimals)
AttributeError: 'PintArray' object has no attribute 'round'

Is there a reasonable way to define what mathods are intended to work on dimensionless units and allow delegation to the array of magnitudes to take place? PintArray does delegation for a number of reduce functions. Perhaps it could delegate for things like rounding as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions