@@ -2175,94 +2175,90 @@ def is_number(obj):
2175
2175
return isinstance (obj , (numbers .Number , np .number ))
2176
2176
2177
2177
2178
- def is_integer_dtype (arr_or_dtype ):
2178
+ def _get_dtype_type (arr_or_dtype ):
2179
2179
if isinstance (arr_or_dtype , np .dtype ):
2180
- tipo = arr_or_dtype .type
2181
- else :
2182
- tipo = arr_or_dtype .dtype .type
2183
- return (issubclass (tipo , np .integer ) and not
2184
- (issubclass (tipo , np .datetime64 ) or
2185
- issubclass (tipo , np .timedelta64 )))
2180
+ return arr_or_dtype .type
2181
+ if isinstance (arr_or_dtype , type ):
2182
+ return np .dtype (arr_or_dtype ).type
2183
+ return arr_or_dtype .dtype .type
2186
2184
2187
2185
2188
- def _is_int_or_datetime_dtype (arr_or_dtype ):
2189
- # also timedelta64
2190
- if isinstance (arr_or_dtype , np .dtype ):
2191
- tipo = arr_or_dtype .type
2192
- else :
2193
- tipo = arr_or_dtype .dtype .type
2186
+ def _is_any_int_dtype (arr_or_dtype ):
2187
+ tipo = _get_dtype_type (arr_or_dtype )
2194
2188
return issubclass (tipo , np .integer )
2195
2189
2196
2190
2191
+ def is_integer_dtype (arr_or_dtype ):
2192
+ tipo = _get_dtype_type (arr_or_dtype )
2193
+ return (issubclass (tipo , np .integer ) and
2194
+ not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
2195
+
2196
+
2197
+ def _is_int_or_datetime_dtype (arr_or_dtype ):
2198
+ tipo = _get_dtype_type (arr_or_dtype )
2199
+ return (issubclass (tipo , np .integer ) or
2200
+ issubclass (tipo , (np .datetime64 , np .timedelta64 )))
2201
+
2202
+
2197
2203
def is_datetime64_dtype (arr_or_dtype ):
2198
- if isinstance (arr_or_dtype , np .dtype ):
2199
- tipo = arr_or_dtype .type
2200
- elif isinstance (arr_or_dtype , type ):
2201
- tipo = np .dtype (arr_or_dtype ).type
2202
- else :
2203
- tipo = arr_or_dtype .dtype .type
2204
+ tipo = _get_dtype_type (arr_or_dtype )
2204
2205
return issubclass (tipo , np .datetime64 )
2205
2206
2206
2207
2207
2208
def is_datetime64_ns_dtype (arr_or_dtype ):
2208
- if isinstance (arr_or_dtype , np .dtype ):
2209
- tipo = arr_or_dtype
2210
- elif isinstance (arr_or_dtype , type ):
2211
- tipo = np .dtype (arr_or_dtype )
2212
- else :
2213
- tipo = arr_or_dtype .dtype
2209
+ tipo = _get_dtype_type (arr_or_dtype )
2214
2210
return tipo == _NS_DTYPE
2215
2211
2216
2212
2217
2213
def is_timedelta64_dtype (arr_or_dtype ):
2218
- if isinstance (arr_or_dtype , np .dtype ):
2219
- tipo = arr_or_dtype .type
2220
- elif isinstance (arr_or_dtype , type ):
2221
- tipo = np .dtype (arr_or_dtype ).type
2222
- else :
2223
- tipo = arr_or_dtype .dtype .type
2214
+ tipo = _get_dtype_type (arr_or_dtype )
2224
2215
return issubclass (tipo , np .timedelta64 )
2225
2216
2226
2217
2227
2218
def is_timedelta64_ns_dtype (arr_or_dtype ):
2228
- if isinstance (arr_or_dtype , np .dtype ):
2229
- tipo = arr_or_dtype .type
2230
- elif isinstance (arr_or_dtype , type ):
2231
- tipo = np .dtype (arr_or_dtype ).type
2232
- else :
2233
- tipo = arr_or_dtype .dtype .type
2219
+ tipo = _get_dtype_type (arr_or_dtype )
2234
2220
return tipo == _TD_DTYPE
2235
2221
2236
2222
2237
- def needs_i8_conversion (arr_or_dtype ):
2238
- return (is_datetime64_dtype (arr_or_dtype ) or
2239
- is_timedelta64_dtype (arr_or_dtype ))
2223
+ def _is_datetime_or_timedelta_dtype (arr_or_dtype ):
2224
+ tipo = _get_dtype_type (arr_or_dtype )
2225
+ return issubclass (tipo , (np .datetime64 , np .timedelta64 ))
2226
+
2227
+
2228
+ needs_i8_conversion = _is_datetime_or_timedelta_dtype
2240
2229
2241
2230
2242
2231
def is_numeric_dtype (arr_or_dtype ):
2243
- if isinstance (arr_or_dtype , np .dtype ):
2244
- tipo = arr_or_dtype .type
2245
- else :
2246
- tipo = arr_or_dtype .dtype .type
2232
+ tipo = _get_dtype_type (arr_or_dtype )
2247
2233
return (issubclass (tipo , (np .number , np .bool_ ))
2248
2234
and not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
2249
2235
2236
+
2250
2237
def is_float_dtype (arr_or_dtype ):
2251
- if isinstance (arr_or_dtype , np .dtype ):
2252
- tipo = arr_or_dtype .type
2253
- else :
2254
- tipo = arr_or_dtype .dtype .type
2238
+ tipo = _get_dtype_type (arr_or_dtype )
2255
2239
return issubclass (tipo , np .floating )
2256
2240
2257
2241
2242
+ def _is_floating_dtype (arr_or_dtype ):
2243
+ tipo = _get_dtype_type (arr_or_dtype )
2244
+ return isinstance (tipo , np .floating )
2245
+
2246
+
2247
+ def is_bool_dtype (arr_or_dtype ):
2248
+ tipo = _get_dtype_type (arr_or_dtype )
2249
+ return issubclass (tipo , np .bool_ )
2250
+
2251
+
2258
2252
def is_complex_dtype (arr_or_dtype ):
2259
- if isinstance (arr_or_dtype , np .dtype ):
2260
- tipo = arr_or_dtype .type
2261
- else :
2262
- tipo = arr_or_dtype .dtype .type
2253
+ tipo = _get_dtype_type (arr_or_dtype )
2263
2254
return issubclass (tipo , np .complexfloating )
2264
2255
2265
2256
2257
+ def is_object_dtype (arr_or_dtype ):
2258
+ tipo = _get_dtype_type (arr_or_dtype )
2259
+ return issubclass (tipo , np .object_ )
2260
+
2261
+
2266
2262
def is_re (obj ):
2267
2263
return isinstance (obj , re ._pattern_type )
2268
2264
0 commit comments