Skip to content

Commit

Permalink
Fixed errors from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnot727 committed Feb 17, 2025
1 parent d504d1b commit 5c33fe5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5c33fe5

Please sign in to comment.