@@ -82,6 +82,8 @@ def _ensure_categorical(arr):
82
82
83
83
84
84
def is_object_dtype (arr_or_dtype ):
85
+ if arr_or_dtype is None :
86
+ return False
85
87
tipo = _get_dtype_type (arr_or_dtype )
86
88
return issubclass (tipo , np .object_ )
87
89
@@ -120,6 +122,8 @@ def is_period(array):
120
122
121
123
122
124
def is_datetime64_dtype (arr_or_dtype ):
125
+ if arr_or_dtype is None :
126
+ return False
123
127
try :
124
128
tipo = _get_dtype_type (arr_or_dtype )
125
129
except TypeError :
@@ -128,23 +132,33 @@ def is_datetime64_dtype(arr_or_dtype):
128
132
129
133
130
134
def is_datetime64tz_dtype (arr_or_dtype ):
135
+ if arr_or_dtype is None :
136
+ return False
131
137
return DatetimeTZDtype .is_dtype (arr_or_dtype )
132
138
133
139
134
140
def is_timedelta64_dtype (arr_or_dtype ):
141
+ if arr_or_dtype is None :
142
+ return False
135
143
tipo = _get_dtype_type (arr_or_dtype )
136
144
return issubclass (tipo , np .timedelta64 )
137
145
138
146
139
147
def is_period_dtype (arr_or_dtype ):
148
+ if arr_or_dtype is None :
149
+ return False
140
150
return PeriodDtype .is_dtype (arr_or_dtype )
141
151
142
152
143
153
def is_interval_dtype (arr_or_dtype ):
154
+ if arr_or_dtype is None :
155
+ return False
144
156
return IntervalDtype .is_dtype (arr_or_dtype )
145
157
146
158
147
159
def is_categorical_dtype (arr_or_dtype ):
160
+ if arr_or_dtype is None :
161
+ return False
148
162
return CategoricalDtype .is_dtype (arr_or_dtype )
149
163
150
164
@@ -178,6 +192,8 @@ def is_string_dtype(arr_or_dtype):
178
192
179
193
# TODO: gh-15585: consider making the checks stricter.
180
194
195
+ if arr_or_dtype is None :
196
+ return False
181
197
try :
182
198
dtype = _get_dtype (arr_or_dtype )
183
199
return dtype .kind in ('O' , 'S' , 'U' ) and not is_period_dtype (dtype )
@@ -224,45 +240,61 @@ def is_dtype_equal(source, target):
224
240
225
241
226
242
def is_any_int_dtype (arr_or_dtype ):
243
+ if arr_or_dtype is None :
244
+ return False
227
245
tipo = _get_dtype_type (arr_or_dtype )
228
246
return issubclass (tipo , np .integer )
229
247
230
248
231
249
def is_integer_dtype (arr_or_dtype ):
250
+ if arr_or_dtype is None :
251
+ return False
232
252
tipo = _get_dtype_type (arr_or_dtype )
233
253
return (issubclass (tipo , np .integer ) and
234
254
not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
235
255
236
256
237
257
def is_signed_integer_dtype (arr_or_dtype ):
258
+ if arr_or_dtype is None :
259
+ return False
238
260
tipo = _get_dtype_type (arr_or_dtype )
239
261
return (issubclass (tipo , np .signedinteger ) and
240
262
not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
241
263
242
264
243
265
def is_unsigned_integer_dtype (arr_or_dtype ):
266
+ if arr_or_dtype is None :
267
+ return False
244
268
tipo = _get_dtype_type (arr_or_dtype )
245
269
return (issubclass (tipo , np .unsignedinteger ) and
246
270
not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
247
271
248
272
249
273
def is_int64_dtype (arr_or_dtype ):
274
+ if arr_or_dtype is None :
275
+ return False
250
276
tipo = _get_dtype_type (arr_or_dtype )
251
277
return issubclass (tipo , np .int64 )
252
278
253
279
254
280
def is_int_or_datetime_dtype (arr_or_dtype ):
281
+ if arr_or_dtype is None :
282
+ return False
255
283
tipo = _get_dtype_type (arr_or_dtype )
256
284
return (issubclass (tipo , np .integer ) or
257
285
issubclass (tipo , (np .datetime64 , np .timedelta64 )))
258
286
259
287
260
288
def is_datetime64_any_dtype (arr_or_dtype ):
289
+ if arr_or_dtype is None :
290
+ return False
261
291
return (is_datetime64_dtype (arr_or_dtype ) or
262
292
is_datetime64tz_dtype (arr_or_dtype ))
263
293
264
294
265
295
def is_datetime64_ns_dtype (arr_or_dtype ):
296
+ if arr_or_dtype is None :
297
+ return False
266
298
try :
267
299
tipo = _get_dtype (arr_or_dtype )
268
300
except TypeError :
@@ -303,6 +335,8 @@ def is_timedelta64_ns_dtype(arr_or_dtype):
303
335
False
304
336
"""
305
337
338
+ if arr_or_dtype is None :
339
+ return False
306
340
try :
307
341
tipo = _get_dtype (arr_or_dtype )
308
342
return tipo == _TD_DTYPE
@@ -311,6 +345,8 @@ def is_timedelta64_ns_dtype(arr_or_dtype):
311
345
312
346
313
347
def is_datetime_or_timedelta_dtype (arr_or_dtype ):
348
+ if arr_or_dtype is None :
349
+ return False
314
350
tipo = _get_dtype_type (arr_or_dtype )
315
351
return issubclass (tipo , (np .datetime64 , np .timedelta64 ))
316
352
@@ -398,12 +434,16 @@ def is_object(x):
398
434
399
435
400
436
def needs_i8_conversion (arr_or_dtype ):
437
+ if arr_or_dtype is None :
438
+ return False
401
439
return (is_datetime_or_timedelta_dtype (arr_or_dtype ) or
402
440
is_datetime64tz_dtype (arr_or_dtype ) or
403
441
is_period_dtype (arr_or_dtype ))
404
442
405
443
406
444
def is_numeric_dtype (arr_or_dtype ):
445
+ if arr_or_dtype is None :
446
+ return False
407
447
tipo = _get_dtype_type (arr_or_dtype )
408
448
return (issubclass (tipo , (np .number , np .bool_ )) and
409
449
not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
@@ -438,6 +478,8 @@ def is_string_like_dtype(arr_or_dtype):
438
478
False
439
479
"""
440
480
481
+ if arr_or_dtype is None :
482
+ return False
441
483
try :
442
484
dtype = _get_dtype (arr_or_dtype )
443
485
return dtype .kind in ('S' , 'U' )
@@ -446,16 +488,22 @@ def is_string_like_dtype(arr_or_dtype):
446
488
447
489
448
490
def is_float_dtype (arr_or_dtype ):
491
+ if arr_or_dtype is None :
492
+ return False
449
493
tipo = _get_dtype_type (arr_or_dtype )
450
494
return issubclass (tipo , np .floating )
451
495
452
496
453
497
def is_floating_dtype (arr_or_dtype ):
498
+ if arr_or_dtype is None :
499
+ return False
454
500
tipo = _get_dtype_type (arr_or_dtype )
455
501
return isinstance (tipo , np .floating )
456
502
457
503
458
504
def is_bool_dtype (arr_or_dtype ):
505
+ if arr_or_dtype is None :
506
+ return False
459
507
try :
460
508
tipo = _get_dtype_type (arr_or_dtype )
461
509
except ValueError :
@@ -479,6 +527,8 @@ def is_extension_type(value):
479
527
480
528
481
529
def is_complex_dtype (arr_or_dtype ):
530
+ if arr_or_dtype is None :
531
+ return False
482
532
tipo = _get_dtype_type (arr_or_dtype )
483
533
return issubclass (tipo , np .complexfloating )
484
534
0 commit comments