-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG-24915 fix unhashble Series.name in df aggregation #24920
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
|
@youhealthy and I are the same person |
Codecov Report
@@ Coverage Diff @@
## master #24920 +/- ##
==========================================
+ Coverage 92.38% 92.38% +<.01%
==========================================
Files 166 166
Lines 52404 52406 +2
==========================================
+ Hits 48412 48414 +2
Misses 3992 3992
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #24920 +/- ##
==========================================
+ Coverage 92.38% 92.38% +<.01%
==========================================
Files 166 166
Lines 52404 52406 +2
==========================================
+ Hits 48412 48414 +2
Misses 3992 3992
Continue to review full report at Codecov.
|
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.
Needs:
- Whatsnew entry for 0.24.1
- Test: Add a test based on the example in the original issue. Construct the DataFrame/Series that replicates the issue and the expected DataFrame/Series
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.
this needs a test. I am also not sure this is actually the correct fix. constructio of a Series from scalars with an invalid name with raise now. IOW this should be raising already, so not sure this is a good remedy.
`
In [1]: Series([1,2],name=[1,2])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-360525e04c11> in <module>
----> 1 Series([1,2],name=[1,2])
~/pandas/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
266 generic.NDFrame.__init__(self, data, fastpath=True)
267
--> 268 self.name = name
269 self._set_axis(0, index, fastpath=True)
270
~/pandas/pandas/core/generic.py in __setattr__(self, name, value)
5077 object.__setattr__(self, name, value)
5078 elif name in self._metadata:
-> 5079 object.__setattr__(self, name, value)
5080 else:
5081 try:
~/pandas/pandas/core/series.py in name(self, value)
400 def name(self, value):
401 if value is not None and not is_hashable(value):
--> 402 raise TypeError('Series.name must be a hashable type')
403 object.__setattr__(self, '_name', value)
404
TypeError: Series.name must be a hashable type
@jreback I agree with you. You can refer to #24915 for the problem. There are 2 ways that I have in mind to fix this:
For 2. What I looked at is #pandas.core.generic.py
if (name in self._internal_names_set or name in self._metadata or
name in self._accessors):
return object.__getattribute__(self, name)
else:
if self._info_axis._can_hold_identifiers_and_holds_name(name):
return self[name]
return object.__getattribute__(self, name)
How do you propose to change? @jreback |
@jreback any idea? |
@lofoyet first thing you need here is a test. Then step thru it until you get to the source of the error, see if you patch fixes. I would rather shy away from changing the way getattr works. Also I am not sure your change is the right way. |
Closing as stale. @lofoyet ping if you'd like to continue though as mentioned above this needs a test first and foremost |
git diff upstream/master -u -- "*.py" | flake8 --diff
Before creating a pd.Series and pass {name} as argument, check if {name} is hashable. If not use default None.