Skip to content

Commit 2b53200

Browse files
committed
BUG: Fix replacing in string series with NA (pandas-dev#32621)
Made improvements based on the tests which failed
1 parent 47f6676 commit 2b53200

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pandas/core/internals/managers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,11 +1936,18 @@ def _compare_or_regex_search(a, b, regex=False):
19361936
is_a_array = isinstance(a, np.ndarray)
19371937
is_b_array = isinstance(b, np.ndarray)
19381938

1939+
def _get_nan_value(x):
1940+
if np.issubdtype(x.dtype, np.datetime64):
1941+
return np.datetime64('NaT')
1942+
elif np.issubdtype(x.dtype, np.timedelta64):
1943+
return np.timedelta64('NaT')
1944+
return np.nan
1945+
19391946
# Replace all definitions of missing values (isna=True) to a numpy.nan
19401947
if is_a_array:
1941-
a = np.where(isna(a), np.nan, a)
1948+
a = np.where(isna(a), _get_nan_value(a), a)
19421949
if is_b_array:
1943-
b = np.where(isna(b), np.nan, b)
1950+
b = np.where(isna(b), _get_nan_value(b), b)
19441951

19451952
if is_datetimelike_v_numeric(a, b) or is_numeric_v_string_like(a, b):
19461953
# GH#29553 avoid deprecation warnings from numpy

0 commit comments

Comments
 (0)