From 5c33fe56ae1b64ebfc1fe0e23d362bf3405a7003 Mon Sep 17 00:00:00 2001 From: Goran Date: Mon, 17 Feb 2025 16:07:57 -0500 Subject: [PATCH] Fixed errors from PR --- pandas/core/algorithms.py | 4 ++-- pandas/core/apply.py | 5 +++-- pandas/core/series.py | 15 ++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 4a5e944c8a100..47ca45e71af98 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1624,7 +1624,7 @@ def union_with_duplicates( repeats = final_count.reindex(unique_vals).values return np.repeat(unique_vals, repeats) - +import pandas as pd def map_array( arr: ArrayLike, mapper, @@ -1698,7 +1698,7 @@ def map_array( # we must convert to python types #values = arr.astype(object, copy=False) - if is_integer_dtype(arr) and is_nullable_dtype(arr.dtype): + if is_integer_dtype(arr) and is_nullable(arr.dtype): def mapper_check(x): if x is None: return pd.NA diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 3d809afd21361..1a178d6c70a97 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -1446,7 +1446,7 @@ def apply_compat(self): except (ValueError, AttributeError, TypeError): result = obj.apply(func, by_row=False) return result - +import pandas as pd def apply_standard(self) -> DataFrame | Series: # caller is responsible for ensuring that f is Callable func = cast(Callable, self.func) @@ -1460,7 +1460,8 @@ def apply_standard(self) -> DataFrame | Series: #Check if type is integer and nullable, return pd.NA for None values and #normal func for other values - if pd.api.types.is_integer_dtype(obj) and pd.api.types.is_nullable_dtype(obj.dtype): + if pd.api.types.is_integer_dtype(obj) and + pd.api.types.is_nullable(obj.dtype): def wrapped_func(x): if x is None: return pd.NA diff --git a/pandas/core/series.py b/pandas/core/series.py index dc08d97c97ee8..9a8902c901540 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4417,7 +4417,8 @@ def map_check(val): if callable(arg): arg = functools.partial(arg, **kwargs) new_values = self._map_values(arg, na_action=na_action) - return self._constructor(new_values, index=self.index, copy=False).__finalize__( + return self._constructor(new_values, index=self.index, copy=False) + .__finalize__( self, method="map" ) @@ -4619,16 +4620,16 @@ def apply( Helsinki 2.484907 dtype: float64 """ - # check if dtype is nullable integer + # check if dtype is nullable integer if pd.api.types.is_integer_dtype(self) and pd.api.types.is_nullable(self.dtype): # def functon to handle NaN as pd.NA - def apply_check(val): - if val is None: - return pd.NA - return val + def apply_check(val): + if val is None: + return pd.NA + return val self = [apply_check(x) for x in self] - #proceed with usual apply method + #proceed with usual apply method return SeriesApply( self, func,