Skip to content

ENH: support CategoricalIndex Followups #9748

Closed
@jreback

Description

@jreback

followup to #9741

These are all commented in pandas/core/test_frame/test_categorical_indexing_index

  • support slice semantics
  • fix index name issue on selection for non-existant label that IS in the categories
  • fix index name issue on assignment for non-existan label that IS in the categories
  • duplicated returns Boolean array? / test
  • in repr, use max_categories/max_seq_len to display a truncated view

These last 2 were 'solved' by putting the following in core/internals/reindex_indexer
but this caused some issues as the MultiIndex._shallow_copy is really a view semantic (so that needs to be fixed as well)

# make sure that we propogate the correct meta data for this axis
# we need to do this because we are not doing a take / reindex
# which would do this automatically
new_axis = self.axes[axis]._shallow_copy(new_axis)
In [1]: In [4]: df = DataFrame({'A' : np.arange(6,dtype='int64'),
   ...:    ...:                 'B' : Series(list('aabbca')).astype('category',categories=list('cabe')) }).set_index('B')

In [2]: df
Out[2]: 
   A
B   
a  0
a  1
b  2
b  3
c  4
a  5

In [3]: df.loc['e'] = 20

In [4]: df
Out[4]: 
    A
a   0
a   1
b   2
b   3
c   4
a   5
e  20

Metadata

Metadata

Assignees

No one assigned

    Labels

    CategoricalCategorical Data TypeEnhancementIndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions