22
22
is_numeric_dtype ,
23
23
needs_i8_conversion ,
24
24
)
25
- from pandas .core .dtypes .dtypes import PandasDtype
25
+ from pandas .core .dtypes .dtypes import (
26
+ CategoricalDtype ,
27
+ PandasDtype ,
28
+ )
26
29
from pandas .core .dtypes .missing import array_equivalent
27
30
28
31
import pandas as pd
@@ -655,7 +658,7 @@ def raise_assert_detail(obj, message, left, right, diff=None, index_values=None)
655
658
if isinstance (left , np .ndarray ):
656
659
left = pprint_thing (left )
657
660
elif (
658
- is_categorical_dtype (left )
661
+ isinstance (left , CategoricalDtype )
659
662
or isinstance (left , PandasDtype )
660
663
or isinstance (left , StringDtype )
661
664
):
@@ -664,7 +667,7 @@ def raise_assert_detail(obj, message, left, right, diff=None, index_values=None)
664
667
if isinstance (right , np .ndarray ):
665
668
right = pprint_thing (right )
666
669
elif (
667
- is_categorical_dtype (right )
670
+ isinstance (right , CategoricalDtype )
668
671
or isinstance (right , PandasDtype )
669
672
or isinstance (right , StringDtype )
670
673
):
@@ -1008,8 +1011,8 @@ def assert_series_equal(
1008
1011
# is False. We'll still raise if only one is a `Categorical`,
1009
1012
# regardless of `check_categorical`
1010
1013
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 )
1013
1016
and not check_categorical
1014
1017
):
1015
1018
pass
@@ -1054,7 +1057,9 @@ def assert_series_equal(
1054
1057
raise AssertionError (msg )
1055
1058
elif is_interval_dtype (left .dtype ) and is_interval_dtype (right .dtype ):
1056
1059
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
+ ):
1058
1063
_testing .assert_almost_equal (
1059
1064
left ._values ,
1060
1065
right ._values ,
@@ -1106,7 +1111,9 @@ def assert_series_equal(
1106
1111
assert_attr_equal ("name" , left , right , obj = obj )
1107
1112
1108
1113
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
+ ):
1110
1117
assert_categorical_equal (
1111
1118
left ._values ,
1112
1119
right ._values ,
@@ -1315,9 +1322,11 @@ def assert_frame_equal(
1315
1322
# compare by columns
1316
1323
else :
1317
1324
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
+
1321
1330
# GH #38183
1322
1331
# use check_index=False, because we do not want to run
1323
1332
# assert_index_equal for each column,
0 commit comments