assert_index_equal checks categories with check_categorical=False · Issue #19776 · pandas-dev/pandas (original) (raw)
The behavior of assert_index_equal
should match assert_series_equal
here with check_categorical=False
.
In [3]: import pandas.util.testing as tm
In [4]: import pandas as pd
In [5]: tm.assert_series_equal( ...: pd.Series(pd.Categorical(['a', 'b'])), ...: pd.Series(pd.Categorical(['a', 'b'], categories=['a', 'b', 'c'])), ...: check_categorical=False ...: )
In [8]: tm.assert_index_equal( ...: pd.Index(pd.Categorical(['a', 'b'])), ...: pd.Index(pd.Categorical(['a', 'b'], categories=['a', 'b', 'c'])), ...: check_categorical=False ...: )
AssertionError Traceback (most recent call last) in () 2 pd.Index(pd.Categorical(['a', 'b'])), 3 pd.Index(pd.Categorical(['a', 'b'], categories=['a', 'b', 'c'])), ----> 4 check_categorical=False 5 )
~/sandbox/pandas-ip/pandas/pandas/util/testing.py in assert_index_equal(left, right, exact, check_names, check_less_precise, check_exact, check_categorical, obj) 798 799 # class / dtype comparison --> 800 _check_types(left, right, obj=obj) 801 802 # level comparison
~/sandbox/pandas-ip/pandas/pandas/util/testing.py in _check_types(l, r, obj) 779 if exact: 780 assert_class_equal(left, right, exact=exact, obj=obj) --> 781 assert_attr_equal('dtype', l, r, obj=obj) 782 # allow string-like to have different inferred_types 783 if l.inferred_type in ('string', 'unicode'):
~/sandbox/pandas-ip/pandas/pandas/util/testing.py in assert_attr_equal(attr, left, right, obj) 921 else: 922 msg = 'Attribute "{attr}" are different'.format(attr=attr) --> 923 raise_assert_detail(obj, msg, left_attr, right_attr) 924 925
~/sandbox/pandas-ip/pandas/pandas/util/testing.py in raise_assert_detail(obj, message, left, right, diff) 1006 msg += "\n[diff]: {diff}".format(diff=diff) 1007 -> 1008 raise AssertionError(msg) 1009 1010
AssertionError: Index are different
Attribute "dtype" are different [left]: CategoricalDtype(categories=['a', 'b'], ordered=False) [right]: CategoricalDtype(categories=['a', 'b', 'c'], ordered=False)