Skip to content

Call finalize in Series.__array_ufunc__ #36553

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
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ Other
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
- Bug in :meth:`Series.transform` would give incorrect results or raise when the argument ``func`` was dictionary (:issue:`35811`)
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
- Fixed metadata propagation in :meth:`Series.abs` and ufuncs called on Series (:issue:`28283`)

.. ---------------------------------------------------------------------------

Expand Down
6 changes: 5 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,11 @@ def construct_return(result):
# GH#27198
raise NotImplementedError
return result
return self._constructor(result, index=index, name=name, copy=False)
# TODO: When we support multiple values in __finalize__, this should
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i understand what you mean, but can you expand on this for readers

# pass alignable instead of self.
return self._constructor(
result, index=index, name=name, copy=False
).__finalize__(self)

if type(result) is tuple:
# multiple return values
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@
(pd.DataFrame, frame_data, operator.inv),
(pd.Series, [1], operator.inv),
(pd.DataFrame, frame_data, abs),
pytest.param((pd.Series, [1], abs), marks=not_implemented_mark),
(pd.Series, [1], abs),
(pd.Series, [1], np.arccos),
pytest.param((pd.DataFrame, frame_data, round), marks=not_implemented_mark),
(pd.Series, [1], round),
(pd.DataFrame, frame_data, operator.methodcaller("take", [0, 0])),
Expand Down