Skip to content

Commit 38d03f9

Browse files
committed
handle replace list with scalar case
1 parent f251aa6 commit 38d03f9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/core/missing.py

+10
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@ def mask_missing(arr, values_to_mask):
3737
except Exception:
3838
values_to_mask = np.array(values_to_mask, dtype=object)
3939

40+
if values_to_mask.ndim == 1 and values_to_mask.size == 0:
41+
values_to_mask = values_to_mask[np.newaxis, :]
42+
4043
na_mask = isna(values_to_mask)
4144
nonna = values_to_mask[~na_mask]
4245

46+
if values_to_mask.ndim == 2 and nonna.ndim == 1:
47+
nonna = nonna[np.newaxis, :]
48+
4349
mask = None
4450
for x in nonna:
4551
if mask is None:
4652

4753
# numpy elementwise comparison warning
4854
if is_numeric_v_string_like(arr, x):
4955
mask = False
56+
elif arr.dtype.kind == 'O':
57+
mask = np.array([i == x.tolist() for i in arr.ravel()])
5058
else:
5159
mask = arr == x
5260

@@ -59,6 +67,8 @@ def mask_missing(arr, values_to_mask):
5967
# numpy elementwise comparison warning
6068
if is_numeric_v_string_like(arr, x):
6169
mask |= False
70+
elif arr.dtype.kind == 'O':
71+
mask |= np.array([i == x.tolist() for i in arr.ravel()])
6272
else:
6373
mask |= arr == x
6474

0 commit comments

Comments
 (0)