Skip to content

TST: assert_series/frame not comparing for categoricals #13076

Closed
@jreback

Description

@jreback

xref dask/partd#7

In [1]: df1 = DataFrame({'A' : Series(list('aba')).astype('category', categories=list('ab'), ordered=True)})

In [2]: df2 = DataFrame({'A' : Series(list('aba')).astype('category', categories=list('ba'), ordered=True)})

In [3]: tm.assert_frame_equal(df1, df2)

In [11]: df2 = DataFrame({'A' : Series(list('aba')).astype('category', categories=list('ab'), ordered=False)})

In [12]: tm.assert_frame_equal(df1, df2)

In [13]: df2 = DataFrame({'A' : Series(list('aba')).astype('category', categories=list('ba'), ordered=False)})

In [14]: tm.assert_frame_equal(df1, df2)

all of these should fail as the ordered categoricals don't compare equal in the categories, and ordered is not being compared (nor categories)

Furthermore the assert_series_equal fail for the same.

assert_categorical_equal DOES the right thing, but not being called here. (not that this should say categories are not equal?)

In [17]: tm.assert_categorical_equal(df1.A.values, df2.A.values)
AssertionError: Index are different

Index values are different (100.0 %)
[left]:  Index([u'a', u'b'], dtype='object')
[right]: Index([u'b', u'a'], dtype='object')

Metadata

Metadata

Assignees

No one assigned

    Labels

    CategoricalCategorical Data TypeTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions