@@ -232,7 +232,7 @@ def _isnull_ndarraylike(obj):
232
232
values = getattr (obj , 'values' , obj )
233
233
dtype = values .dtype
234
234
235
- if dtype . kind in ( 'O' , 'S' , 'U' ):
235
+ if is_string_dtype ( dtype ):
236
236
if is_categorical_dtype (values ):
237
237
from pandas import Categorical
238
238
if not isinstance (values , Categorical ):
@@ -243,7 +243,7 @@ def _isnull_ndarraylike(obj):
243
243
# Working around NumPy ticket 1542
244
244
shape = values .shape
245
245
246
- if dtype . kind in ( 'S' , 'U' ):
246
+ if is_string_like_dtype ( dtype ):
247
247
result = np .zeros (values .shape , dtype = bool )
248
248
else :
249
249
result = np .empty (shape , dtype = bool )
@@ -267,11 +267,11 @@ def _isnull_ndarraylike_old(obj):
267
267
values = getattr (obj , 'values' , obj )
268
268
dtype = values .dtype
269
269
270
- if dtype . kind in ( 'O' , 'S' , 'U' ):
270
+ if is_string_dtype ( dtype ):
271
271
# Working around NumPy ticket 1542
272
272
shape = values .shape
273
273
274
- if values . dtype . kind in ( 'S' , 'U' ):
274
+ if is_string_like_dtype ( dtype ):
275
275
result = np .zeros (values .shape , dtype = bool )
276
276
else :
277
277
result = np .empty (shape , dtype = bool )
@@ -2208,13 +2208,17 @@ def is_numeric_v_string_like(a, b):
2208
2208
2209
2209
is_a_numeric_array = is_a_array and is_numeric_dtype (a )
2210
2210
is_b_numeric_array = is_b_array and is_numeric_dtype (b )
2211
+ is_a_string_array = is_a_array and is_string_like_dtype (a )
2212
+ is_b_string_array = is_b_array and is_string_like_dtype (b )
2211
2213
2212
2214
is_a_scalar_string_like = not is_a_array and is_string_like (a )
2213
2215
is_b_scalar_string_like = not is_b_array and is_string_like (b )
2214
2216
2215
2217
return (
2216
2218
is_a_numeric_array and is_b_scalar_string_like ) or (
2217
- is_b_numeric_array and is_a_scalar_string_like
2219
+ is_b_numeric_array and is_a_scalar_string_like ) or (
2220
+ is_a_numeric_array and is_b_string_array ) or (
2221
+ is_b_numeric_array and is_a_string_array
2218
2222
)
2219
2223
2220
2224
def is_datetimelike_v_numeric (a , b ):
@@ -2257,6 +2261,15 @@ def is_numeric_dtype(arr_or_dtype):
2257
2261
and not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
2258
2262
2259
2263
2264
+ def is_string_dtype (arr_or_dtype ):
2265
+ dtype = _get_dtype (arr_or_dtype )
2266
+ return dtype .kind in ('O' , 'S' , 'U' )
2267
+
2268
+ def is_string_like_dtype (arr_or_dtype ):
2269
+ # exclude object as its a mixed dtype
2270
+ dtype = _get_dtype (arr_or_dtype )
2271
+ return dtype .kind in ('S' , 'U' )
2272
+
2260
2273
def is_float_dtype (arr_or_dtype ):
2261
2274
tipo = _get_dtype_type (arr_or_dtype )
2262
2275
return issubclass (tipo , np .floating )
0 commit comments