Skip to content

df.reorder_levels() ... drops name attribute of DataFrame #3576

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
sanguineturtle opened this issue May 11, 2013 · 4 comments
Closed

df.reorder_levels() ... drops name attribute of DataFrame #3576

sanguineturtle opened this issue May 11, 2013 · 4 comments
Labels
Duplicate Report Duplicate issue or pull request

Comments

@sanguineturtle
Copy link

Using Pandas 0.11.0
A DataFrame with MultiIndex:

df = df.reorder_levels() drops the dataframe name attribute.

thus, df.name after the reorder_levels() has no attribute 'name'

@cpcloud
Copy link
Member

cpcloud commented May 13, 2013

@sanguineturtle DataFrame does not have a name attribute by default. As you probably know, though, Python objects have a __dict__ attribute which is the instance's namespace and that allows one to assign arbitrary attributes at runtime to an instance (or a class). The reason name is getting dropped from this particular DataFrame instance is just that, you've assigned an attribute to an instance of a class and thus when reorder_levels creates a new instance that new instance correspondingly has a new namespace. You can assign a class variable if you want. So, this is not really an issue so much as a feature (or bug if you're feeling pessimistic) of the Python object model/runtime.

@sanguineturtle
Copy link
Author

I see. Agreed - this is more along the lines of a feature request. The reason I like to have the DataFrame name attribute propagate is that I am using pandas to track 'labelled' matrices. I have a function that takes a DataFrame converts it to a matrix for computation and the returns it as a DataFrame. Therefore, when I do relevant data manipulations (such as reorder_levels()), it would be helpful for the name label to persist as a label of the overall matrix data. (i.e. country-product level export data).

The main benefit is that the matrix data can then be sorted and matched with other relevant data sources along their relevant axis (axis=0 and axis=1). Is there a Features Register?

@cpcloud
Copy link
Member

cpcloud commented May 13, 2013

A more general version of what you want is in the works, see #2485. And the name attribute is slated for 0.12, see #447.

@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

closing this in favor of the above referenced issues

@jreback jreback closed this as completed Jun 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants