Skip to content

Commit 68083c8

Browse files
committed
WARN: more elementwise comparisons to object
1 parent 86d4590 commit 68083c8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pandas/core/common.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,24 @@ def mask_missing(arr, values_to_mask):
444444
mask = None
445445
for x in nonna:
446446
if mask is None:
447-
mask = arr == x
447+
448+
# numpy elementwise comparison warning
449+
if is_numeric_dtype(arr) and is_string_like(x):
450+
mask = False
451+
else:
452+
mask = arr == x
448453

449454
# if x is a string and arr is not, then we get False and we must
450455
# expand the mask to size arr.shape
451456
if np.isscalar(mask):
452457
mask = np.zeros(arr.shape, dtype=bool)
453458
else:
454-
mask |= arr == x
459+
460+
# numpy elementwise comparison warning
461+
if is_numeric_dtype(arr) and is_string_like(x):
462+
mask |= False
463+
else:
464+
mask |= arr == x
455465

456466
if na_mask.any():
457467
if mask is None:
@@ -2382,6 +2392,9 @@ def _maybe_make_list(obj):
23822392
is_complex = lib.is_complex
23832393

23842394

2395+
def is_string_like(obj):
2396+
return isinstance(obj, (compat.text_type, compat.string_types))
2397+
23852398
def is_iterator(obj):
23862399
# python 3 generators have __next__ instead of next
23872400
return hasattr(obj, 'next') or hasattr(obj, '__next__')

pandas/core/internals.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
is_datetime64tz_dtype, is_datetimetz, is_sparse,
1818
array_equivalent, _maybe_convert_string_to_object,
1919
is_categorical, needs_i8_conversion, is_datetimelike_v_numeric,
20-
is_internal_type)
20+
is_string_like, is_internal_type)
2121
from pandas.core.dtypes import DatetimeTZDtype
2222

2323
from pandas.core.index import Index, MultiIndex, _ensure_index
@@ -1085,6 +1085,11 @@ def get_result(other):
10851085
# avoid numpy warning of comparisons again None
10861086
if other is None:
10871087
result = not func.__name__ == 'eq'
1088+
1089+
# avoid numpy warning of elementwise comparisons to object
1090+
elif self.is_numeric and is_string_like(other):
1091+
result = False
1092+
10881093
else:
10891094
result = func(values, other)
10901095

0 commit comments

Comments
 (0)