@@ -2175,94 +2175,90 @@ def is_number(obj):
21752175 return isinstance (obj , (numbers .Number , np .number ))
21762176
21772177
2178- def is_integer_dtype (arr_or_dtype ):
2178+ def _get_dtype_type (arr_or_dtype ):
21792179 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
21862184
21872185
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 )
21942188 return issubclass (tipo , np .integer )
21952189
21962190
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+
21972203def 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 )
22042205 return issubclass (tipo , np .datetime64 )
22052206
22062207
22072208def 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 )
22142210 return tipo == _NS_DTYPE
22152211
22162212
22172213def 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 )
22242215 return issubclass (tipo , np .timedelta64 )
22252216
22262217
22272218def 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 )
22342220 return tipo == _TD_DTYPE
22352221
22362222
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
22402229
22412230
22422231def 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 )
22472233 return (issubclass (tipo , (np .number , np .bool_ ))
22482234 and not issubclass (tipo , (np .datetime64 , np .timedelta64 )))
22492235
2236+
22502237def 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 )
22552239 return issubclass (tipo , np .floating )
22562240
22572241
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+
22582252def 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 )
22632254 return issubclass (tipo , np .complexfloating )
22642255
22652256
2257+ def is_object_dtype (arr_or_dtype ):
2258+ tipo = _get_dtype_type (arr_or_dtype )
2259+ return issubclass (tipo , np .object_ )
2260+
2261+
22662262def is_re (obj ):
22672263 return isinstance (obj , re ._pattern_type )
22682264
0 commit comments