Skip to content

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

Closed

Conversation

chinskiy
Copy link

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.

@jreback
Copy link
Contributor

jreback commented Mar 13, 2016

we already have an pandas.core.common.is_hashable just use this

@jreback
Copy link
Contributor

jreback commented Mar 13, 2016

but this needs to be checked more generally (higher up in the constructor)

prob need a few more tests

@chinskiy
Copy link
Author

ok.

@chinskiy chinskiy closed this Mar 13, 2016
@jreback
Copy link
Contributor

jreback commented Mar 13, 2016

no reason to close
just update push again

@jreback jreback reopened this Mar 13, 2016
@jreback jreback changed the title BUG GH12610 fix BUG: ensure Series.name is hashable, #12610 Mar 14, 2016
@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label Mar 14, 2016
@jreback
Copy link
Contributor

jreback commented Mar 17, 2016

actually I realize that the ref issue #9193 was not merged.

can you rebase/update this. Then add the .name attribute like was one there?

(this covers setting as well).

further for the actual tests

lets test both the constructor and setting with:

  • a bunch of invalid things (you did some already: dict, np.array, list)
  • a bunch of valid things (int, float, string, datetime, tuple)

@jreback jreback added this to the 0.18.1 milestone Mar 17, 2016
@chinskiy
Copy link
Author

Okay, I will try to do this soon.
Additional test - not problem.

add .name atribute - you mean about:

@property
def name(self):
    return self._name

@name.setter
def name(self, value):
    if is_hashable(value):

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.

@jreback
Copy link
Contributor

jreback commented Mar 17, 2016

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 .name to set the name as well (where all of the checking should actually happen).

Thanks for the wiki update! cool!

@chinskiy chinskiy force-pushed the pandas_series_name_attribute branch from e86b75b to 7111a7e Compare March 20, 2016 18:26
@name.setter
def name(self, value):
if value is not None:
if com.is_hashable(value):
Copy link
Contributor

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)

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Contributor

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.

@jreback
Copy link
Contributor

jreback commented Mar 20, 2016

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)

Copy link
Author

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

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Author

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.

@chinskiy chinskiy force-pushed the pandas_series_name_attribute branch from 4be64b4 to 629d28e Compare March 22, 2016 23:19
@chinskiy chinskiy force-pushed the pandas_series_name_attribute branch from 629d28e to 5c3f1c5 Compare March 22, 2016 23:39




Copy link
Contributor

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

jreback pushed a commit to jreback/pandas that referenced this pull request Mar 25, 2016
@jreback jreback closed this in 26c7d8d Mar 25, 2016
@jreback
Copy link
Contributor

jreback commented Mar 25, 2016

thanks @chinskiy keep em coming!

@chinskiy chinskiy deleted the pandas_series_name_attribute branch March 25, 2016 17:02
@chinskiy chinskiy restored the pandas_series_name_attribute branch March 25, 2016 17:02
@chinskiy chinskiy deleted the pandas_series_name_attribute branch March 25, 2016 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Pandas Series name attribute can be array
2 participants