New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert_index_equal checks categories with check_categorical=False #19776

Closed
TomAugspurger opened this Issue Feb 19, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@TomAugspurger
Contributor

TomAugspurger commented Feb 19, 2018

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)
<ipython-input-8-554e162c7f12> in <module>()
      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)

@TomAugspurger TomAugspurger added this to the Next Major Release milestone Feb 19, 2018

@alysivji

This comment has been minimized.

Contributor

alysivji commented May 14, 2018

I'll tackle this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment