-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: ensure Series.name is hashable, #12610 #12612
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
we already have an pandas.core.common.is_hashable just use this |
but this needs to be checked more generally (higher up in the constructor) prob need a few more tests |
ok. |
no reason to close |
actually I realize that the ref issue #9193 was not merged. can you rebase/update this. Then add the (this covers setting as well). further for the actual tests lets test both the constructor and setting with:
|
Okay, I will try to do this soon. add
P.S. Not a topic of this conversation: yesterday I add to wiki translation about Pandas on Ukrainian https://uk.wikipedia.org/wiki/Pandas - think it's useful. |
Yes, if you take pretty that other PR and incorporate would be great. You can prob remove the explicit check in the constructor as it will use Thanks for the wiki update! cool! |
e86b75b
to
7111a7e
Compare
@name.setter | ||
def name(self, value): | ||
if value is not None: | ||
if com.is_hashable(value): |
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.
@name.setter
def name(self, value):
if value is not None and not com.is_hashable(value):
raise .......
object.__setattr__(self, '_name', None)
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, but how better add object.__setattr__(self, '_name', value)
to this code?
object.__setattr__(self, '_name', None)
only if name
attribute not added.
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.
name
should NEVER be defined, only _name
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.
That's why the pickling tests are important. I think this should work (as old pickles have a .name
instance variable); we are now converting it when set to a ._name
, but should be transparent to the user.
I think you might need to change: https://github.com/pydata/pandas/blob/master/pandas/core/series.py#L235 as well (and look and see if anywhere else is doing something similar) |
if name is not None and not com.is_hashable(name): | ||
raise TypeError('Series.name must be a hashable type') | ||
object.__setattr__(self, '_name', name) | ||
|
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.
Not sure that correctly understood here and with _name below
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.
you are duplicating code here.
just self.name = name
(this will then hit the setattr property)
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.
that's all I meant was to change it to a more 'normal' setter
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.
sorry, my fault, don't understand. I'm just studying, will make it as it must be.
4be64b4
to
629d28e
Compare
629d28e
to
5c3f1c5
Compare
|
||
|
||
|
||
|
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.
just put this higher up, in the existing space, so you aren't adding lines
thanks @chinskiy keep em coming! |
git diff upstream/master | flake8 --diff
pandas >= 0.18.0 will no longer support compatibility with Python version 2.6 and since Python 2.6 we can use the abstract base class collections.Hashable.