File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 2
2
import numpy as np
3
3
4
4
from pandas import compat
5
+ from pandas .core .dtypes .generic import ABCSeries , ABCIndexClass , ABCDataFrame
5
6
from pandas .errors import AbstractMethodError
6
7
7
8
@@ -83,7 +84,12 @@ def is_dtype(cls, dtype):
83
84
"""
84
85
dtype = getattr (dtype , 'dtype' , dtype )
85
86
86
- if isinstance (dtype , np .dtype ):
87
+ if isinstance (dtype , (ABCSeries , ABCIndexClass ,
88
+ ABCDataFrame , np .dtype )):
89
+ # https://github.com/pandas-dev/pandas/issues/22960
90
+ # avoid passing data to `construct_from_string`. This could
91
+ # cause a FutureWarning from numpy about failing elementwise
92
+ # comparison from, e.g., comparing DataFrame == 'category'.
87
93
return False
88
94
elif dtype is None :
89
95
return False
Original file line number Diff line number Diff line change @@ -815,3 +815,23 @@ def test_registry_find(dtype, expected):
815
815
('datetime64[ns, US/Eastern]' , DatetimeTZDtype ('ns' , 'US/Eastern' ))])
816
816
def test_pandas_registry_find (dtype , expected ):
817
817
assert _pandas_registry .find (dtype ) == expected
818
+
819
+
820
+ @pytest .mark .parametrize ("check" , [
821
+ is_categorical_dtype ,
822
+ is_datetime64tz_dtype ,
823
+ is_period_dtype ,
824
+ is_datetime64_ns_dtype ,
825
+ is_datetime64_dtype ,
826
+ is_interval_dtype ,
827
+ is_datetime64_any_dtype ,
828
+ is_string_dtype ,
829
+ is_bool_dtype ,
830
+ ])
831
+ def test_is_dtype_no_warning (check ):
832
+ data = pd .DataFrame ({"A" : [1 , 2 ]})
833
+ with tm .assert_produces_warning (None ):
834
+ check (data )
835
+
836
+ with tm .assert_produces_warning (None ):
837
+ check (data ["A" ])
You can’t perform that action at this time.
0 commit comments