Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Mar 20, 2016

@sinhrks sinhrks added Bug Categorical Categorical Data Type labels Mar 20, 2016
@sinhrks sinhrks added this to the 0.18.1 milestone Mar 20, 2016
@@ -37,7 +37,7 @@ class CategoricalIndex(Index, base.PandasDelegate):

_typ = 'categoricalindex'
_engine_type = _index.Int64Engine
_attributes = ['name']
_attributes = ['name', 'categories', 'ordered']
Copy link
Contributor

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.

Copy link
Member Author

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):
Copy link
Contributor

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.

Copy link
Member Author

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')

@jreback
Copy link
Contributor

jreback commented Mar 22, 2016

@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 CategoricalIndex._simple_new to Categorical_index._shallow_copy (and then change things that use _simple_new. It might not have been exactly clean to start.

@sinhrks
Copy link
Member Author

sinhrks commented Mar 24, 2016

@jreback Current CategoricalIndex._simple_new follows the above definition (not rely on metadata at all).

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):
Copy link
Contributor

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

@jreback
Copy link
Contributor

jreback commented Mar 29, 2016

thanks @sinhrks always nice PR's!

@sinhrks sinhrks deleted the describe_cat branch March 29, 2016 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

groupby categorical column fails with unstack
2 participants