From 554fa2b3fb3c9f6ad3369bbb506abead50f4c3bc Mon Sep 17 00:00:00 2001 From: Ryan Yao Date: Thu, 20 Apr 2023 14:08:37 -0400 Subject: [PATCH 1/3] added fix for fillna bug --- pandas/core/arrays/masked.py | 5 +++-- pandas/core/generic.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 576a75de9962c..e5769ad0053ba 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -166,7 +166,6 @@ def fillna(self, value=None, method=None, limit: int | None = None) -> Self: value, method = validate_fillna_kwargs(value, method) mask = self._mask - if is_array_like(value): if len(value) != len(self): raise ValueError( @@ -185,6 +184,8 @@ def fillna(self, value=None, method=None, limit: int | None = None) -> Self: else: # fill with value new_values = self.copy() + if np.isneginf(value) or np.isinf(value): + new_values = new_values.astype(np.float64) new_values[mask] = value else: new_values = self.copy() @@ -218,7 +219,7 @@ def _validate_setitem_value(self, value): if lib.is_integer(value) or (lib.is_float(value) and value.is_integer()): return value # TODO: unsigned checks - + print(self.dtype) # Note: without the "str" here, the f-string rendering raises in # py38 builds. raise TypeError(f"Invalid value '{str(value)}' for dtype {self.dtype}") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 492fcff5c4f87..d628443be15f4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6995,7 +6995,6 @@ def fillna( "or Series, but you passed a " f'"{type(value).__name__}"' ) - new_data = self._mgr.fillna( value=value, limit=limit, inplace=inplace, downcast=downcast ) @@ -8278,6 +8277,7 @@ def clip( # GH 19992 # numpy doesn't drop a list-like bound containing NaN isna_lower = isna(lower) + print(isna_lower) if not is_list_like(lower): if np.any(isna_lower): lower = None From c6f1360ac1e8839a14fb844d9989d73c0d479514 Mon Sep 17 00:00:00 2001 From: Ryan Yao Date: Thu, 20 Apr 2023 14:11:18 -0400 Subject: [PATCH 2/3] removed print statements --- pandas/core/arrays/masked.py | 3 ++- pandas/core/generic.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index e5769ad0053ba..1316e609d31b8 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -166,6 +166,7 @@ def fillna(self, value=None, method=None, limit: int | None = None) -> Self: value, method = validate_fillna_kwargs(value, method) mask = self._mask + if is_array_like(value): if len(value) != len(self): raise ValueError( @@ -219,7 +220,7 @@ def _validate_setitem_value(self, value): if lib.is_integer(value) or (lib.is_float(value) and value.is_integer()): return value # TODO: unsigned checks - print(self.dtype) + # Note: without the "str" here, the f-string rendering raises in # py38 builds. raise TypeError(f"Invalid value '{str(value)}' for dtype {self.dtype}") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d628443be15f4..492fcff5c4f87 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6995,6 +6995,7 @@ def fillna( "or Series, but you passed a " f'"{type(value).__name__}"' ) + new_data = self._mgr.fillna( value=value, limit=limit, inplace=inplace, downcast=downcast ) @@ -8277,7 +8278,6 @@ def clip( # GH 19992 # numpy doesn't drop a list-like bound containing NaN isna_lower = isna(lower) - print(isna_lower) if not is_list_like(lower): if np.any(isna_lower): lower = None From 077f74d00fa29d4653333b8b8aec8f6dfb562349 Mon Sep 17 00:00:00 2001 From: Ryan Yao Date: Thu, 20 Apr 2023 14:12:08 -0400 Subject: [PATCH 3/3] removed spacing --- pandas/core/arrays/masked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 1316e609d31b8..3a4752268f4d6 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -220,7 +220,7 @@ def _validate_setitem_value(self, value): if lib.is_integer(value) or (lib.is_float(value) and value.is_integer()): return value # TODO: unsigned checks - + # Note: without the "str" here, the f-string rendering raises in # py38 builds. raise TypeError(f"Invalid value '{str(value)}' for dtype {self.dtype}")