2222 is_numeric_dtype ,
2323 needs_i8_conversion ,
2424)
25- from pandas .core .dtypes .dtypes import PandasDtype
25+ from pandas .core .dtypes .dtypes import (
26+ CategoricalDtype ,
27+ PandasDtype ,
28+ )
2629from pandas .core .dtypes .missing import array_equivalent
2730
2831import pandas as pd
@@ -655,7 +658,7 @@ def raise_assert_detail(obj, message, left, right, diff=None, index_values=None)
655658 if isinstance (left , np .ndarray ):
656659 left = pprint_thing (left )
657660 elif (
658- is_categorical_dtype (left )
661+ isinstance (left , CategoricalDtype )
659662 or isinstance (left , PandasDtype )
660663 or isinstance (left , StringDtype )
661664 ):
@@ -664,7 +667,7 @@ def raise_assert_detail(obj, message, left, right, diff=None, index_values=None)
664667 if isinstance (right , np .ndarray ):
665668 right = pprint_thing (right )
666669 elif (
667- is_categorical_dtype (right )
670+ isinstance (right , CategoricalDtype )
668671 or isinstance (right , PandasDtype )
669672 or isinstance (right , StringDtype )
670673 ):
@@ -1008,8 +1011,8 @@ def assert_series_equal(
10081011 # is False. We'll still raise if only one is a `Categorical`,
10091012 # regardless of `check_categorical`
10101013 if (
1011- is_categorical_dtype (left .dtype )
1012- and is_categorical_dtype (right .dtype )
1014+ isinstance (left .dtype , CategoricalDtype )
1015+ and isinstance (right .dtype , CategoricalDtype )
10131016 and not check_categorical
10141017 ):
10151018 pass
@@ -1054,7 +1057,9 @@ def assert_series_equal(
10541057 raise AssertionError (msg )
10551058 elif is_interval_dtype (left .dtype ) and is_interval_dtype (right .dtype ):
10561059 assert_interval_array_equal (left .array , right .array )
1057- elif is_categorical_dtype (left .dtype ) or is_categorical_dtype (right .dtype ):
1060+ elif isinstance (left .dtype , CategoricalDtype ) or isinstance (
1061+ right .dtype , CategoricalDtype
1062+ ):
10581063 _testing .assert_almost_equal (
10591064 left ._values ,
10601065 right ._values ,
@@ -1106,7 +1111,9 @@ def assert_series_equal(
11061111 assert_attr_equal ("name" , left , right , obj = obj )
11071112
11081113 if check_categorical :
1109- if is_categorical_dtype (left .dtype ) or is_categorical_dtype (right .dtype ):
1114+ if isinstance (left .dtype , CategoricalDtype ) or isinstance (
1115+ right .dtype , CategoricalDtype
1116+ ):
11101117 assert_categorical_equal (
11111118 left ._values ,
11121119 right ._values ,
@@ -1315,9 +1322,11 @@ def assert_frame_equal(
13151322 # compare by columns
13161323 else :
13171324 for i , col in enumerate (left .columns ):
1318- assert col in right
1319- lcol = left .iloc [:, i ]
1320- rcol = right .iloc [:, i ]
1325+ # We have already checked that columns match, so we can do
1326+ # fast location-based lookups
1327+ lcol = left ._ixs (i , axis = 1 )
1328+ rcol = right ._ixs (i , axis = 1 )
1329+
13211330 # GH #38183
13221331 # use check_index=False, because we do not want to run
13231332 # assert_index_equal for each column,
0 commit comments