Skip to content

Added warning about attribute access on 'reserved' words #8100

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 2 commits into from

Conversation

FragLegs
Copy link
Contributor

closes #8082

@jreback jreback added the Docs label Aug 28, 2014
@jreback jreback added this to the 0.15.0 milestone Aug 28, 2014
@@ -233,6 +233,12 @@ new column.

- The attribute will not be available if it conflicts with an existing method name, e.g. ``s.min`` is not allowed.

- Similarly, the attribute will not be available if it conflicts with any of the following list: index, major_axis,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put backticks around each element of the list: index, major_axis...etc

@jreback
Copy link
Contributor

jreback commented Sep 4, 2014

@FragLegs can you update?

@FragLegs
Copy link
Contributor Author

FragLegs commented Sep 4, 2014

Sorry for the delay - been on vacation.

@jtratner
Copy link
Contributor

jtratner commented Sep 7, 2014

Should we also have a warning on creation (or a different Attribute Error)?

maybe this should be a warning on creation? I.e.:

>>> DataFrame(some_data, columns=['labels', 'val', 'fun'])
UserWarning: Using reserved column name `labels` will be inaccessible by `getattr` calls - you must use `[]` instead.

or maybe we could raise a differently phrased attribute error:

>>> df = pandas.DataFrame(columns=['labels'])
>>> df['labels']
Series([], name: labels, dtype: object)
>>> df.labels
AttributeError: 'DataFrame' object has no indexer 'labels'.

though I'm not sure that's clearer :P . (see jtratner/pandas@c1cee7d for the potential diff)

Would that error message have helped @FragLegs ?

@FragLegs
Copy link
Contributor Author

FragLegs commented Sep 9, 2014

@jtratner I'm not sure. If I had gotten that error message, I would have still been left wondering, "Why doesn't it have a labels attribute? I know it's there." The warning on creation would be more helpful, or perhaps an error message that has some of that warning's flavor:

AttributeError: 'DataFrame' object has no indexer 'labels' - use `[]` instead.

Of course that would require checking to see if the attribute does exist as a column during the error handling, which feels a little hacky. I do agree that it would be helpful to have something more in the error or warning messages though, especially since searching the documentation for these keywords will probably not get you to the needed information very easily.

@jreback
Copy link
Contributor

jreback commented Sep 9, 2014

@FragLegs can you squash into a single pls. ping when green.

@jtratner
Copy link
Contributor

jtratner commented Sep 9, 2014

well, whatever error message we pick, we can put the exact text in the docs
so it comes up if you search on Google.

@jreback
Copy link
Contributor

jreback commented Sep 13, 2014

merged via 9b12ccb

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'labels' as a DataFrame column name in version 0.14.1
3 participants