-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
@@ -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, |
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.
put backticks around each element of the list: index
, major_axis
...etc
@FragLegs can you update? |
Sorry for the delay - been on vacation. |
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 ? |
@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:
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. |
@FragLegs can you squash into a single pls. ping when green. |
well, whatever error message we pick, we can put the exact text in the docs |
merged via 9b12ccb thanks! |
closes #8082