-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: .describe lost CategoricalIndex info #12675
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
Conversation
@@ -37,7 +37,7 @@ class CategoricalIndex(Index, base.PandasDelegate): | |||
|
|||
_typ = 'categoricalindex' | |||
_engine_type = _index.Int64Engine | |||
_attributes = ['name'] | |||
_attributes = ['name', 'categories', 'ordered'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should't be part of attributes. These are actual properties already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fixed not to use _attributes
.
@@ -136,6 +136,19 @@ def _simple_new(cls, values, name=None, categories=None, ordered=None, | |||
result._reset_identity() | |||
return result | |||
|
|||
@Appender(_index_shared_docs['_shallow_copy']) | |||
def _shallow_copy(self, values=None, categories=None, ordered=None, | |||
**kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why this is necessary, the _simple_new
already handles this, if categories
or ordered
is not None
they will be set, otherwise they won't and will simply be a refernce to the data, which is a CategoricalIndex
at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback Not now, because _simple_new
is a class method.
# on current master
pd.CategoricalIndex([1, 2, 3], ordered=True)._simple_new([1, 2])
# CategoricalIndex([1, 2], categories=[1, 2], ordered=False, dtype='category')
@sinhrks yeah that looks right. Pls have a quick look thru the index classes and confirm if that's really what we are doing for the rest. You might even be able to lift some of the stuff off of |
@jreback Current https://github.com/pydata/pandas/blob/master/pandas/indexes/category.py#L126 |
@@ -340,6 +339,8 @@ def _shallow_copy(self, values=None, **kwargs): | |||
values : the values to create the new Index, optional | |||
kwargs : updates the default attributes for this Index | |||
""" | |||
@Appender(_index_shared_docs['_shallow_copy']) | |||
def _shallow_copy(self, values=None, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we have _shallow_copy
defined for any other classes if so need to add docs like u did here
thanks @sinhrks always nice PR's! |
git diff upstream/master | flake8 --diff
groupby categorical column fails with unstack #11558 is partially fixed by BUG: CategoricalIndex.get_loc returns array even if it is unique #12531, this PR let
.describe()
to preserveCategoricalIndex
info. And added explicit test cases derived from groupby categorical column fails with unstack #11558.