Skip to content

Commit 2c6de3c

Browse files
Implement map also for Pandas 2.0.2
Implement `map` for PintArrays also only with Pandas 2.0.2 interfaces. Signed-off-by: Michael Tiemann <[email protected]>
1 parent 9ff7179 commit 2c6de3c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGES

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ pint-pandas Changelog
55
----------------
66

77
<<<<<<< HEAD
8-
- Support for Pandas version 2.1.0 (including dtype-preserving `PintArray.map`) #196
8+
- Support for Pandas version 2.1.0. #196
9+
- Support for dtype-preserving `PintArray.map` for both Pandas 2.0.2 and Pandas 2.1. #196
910
- Support for <NA> values in columns with integer magnitudes
1011
- Support for magnitudes of any type, such as complex128 or tuples #146
1112
- Support for pandas 2.0, allowing `.cumsum, .cummax, .cummin` methods for `Series` and `DataFrame`. #186

pint_pandas/pint_array.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,14 @@ def map(self, mapper, na_action=None):
844844
If mapper is a function, operate on the magnitudes of the array and
845845
846846
"""
847-
from pandas.core.algorithms import map_array
847+
if pandas_version_info < (2, 1):
848+
ser = pd.Series(self._to_array_of_quantity())
849+
arr = ser.map(mapper, na_action).values
850+
else:
851+
from pandas.core.algorithms import map_array
852+
853+
arr = map_array(self, mapper, na_action)
848854

849-
arr = map_array(self, mapper, na_action)
850855
master_scalar = None
851856
try:
852857
master_scalar = next(i for i in arr if hasattr(i, "units"))

0 commit comments

Comments
 (0)