-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
call __finalize__ in more methods #37186
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
0cc664f
to
b1747d2
Compare
lgtm. |
return stack(self, level, dropna=dropna) | ||
result = stack(self, level, dropna=dropna) | ||
|
||
return result.__finalize__(self, method="stack") |
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.
I think this falls into the name
issue I spotted in #37037. Essentially, if df
has a column named name
we try to set result.name = self.name
, i.e. the series name
.
In [10]: df = pd.DataFrame({"A": [1, 2], "name": [3, 4]})
In [11]: df.stack().__finalize__(df)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-899f15844169> in <module>
----> 1 df.stack().__finalize__(df)
~/Envs/dask-dev/lib/python3.8/site-packages/pandas/core/generic.py in __finalize__(self, other, method, **kwargs)
5157 if isinstance(other, NDFrame):
5158 for name in self._metadata:
-> 5159 object.__setattr__(self, name, getattr(other, name, None))
5160 return self
5161
~/Envs/dask-dev/lib/python3.8/site-packages/pandas/core/series.py in name(self, value)
464 def name(self, value):
465 if value is not None and not is_hashable(value):
--> 466 raise TypeError("Series.name must be a hashable type")
467 object.__setattr__(self, "_name", value)
468
TypeError: Series.name must be a hashable type
I'll think the solution is to only iterate over the intersection of self._metadata
and other._metadata
. I'll put up a PR.
#37205 handles the dataframe.name issue. I don't know if we want to add a test case for all of those, but one or two might not hurt? |
can you merge master and ping on green as merged @TomAugspurger patch |
b1747d2
to
8475562
Compare
Green |
thanks @arw2019 |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
The goal here is to make progress on some of the more uncontroversial/easier content of #28283. I'll split off into another PR if this gets too big