Skip to content

CLN: unify __finalize__ treatment for Series ops #28590

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

Merged
merged 3 commits into from
Sep 26, 2019

Conversation

jbrockmendel
Copy link
Member

ATM we have three slightly different usages for the arithmetic, comparison and logical ops, with no clear reason for the differences. This changes that to make the arithmetic the one true version, which has the added benefit of letting us share _construct_result code across these three functions.

result = finalizer(result)

# Set the result's name after finalizer is called because finalizer
# would set it back to self.name
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this comment inside the construct_result function?

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, will do

lambda x: x.__finalize__(self)
if isinstance(other, (np.ndarray, ABCIndexClass))
else x
)
Copy link
Member

Choose a reason for hiding this comment

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

Now it will always be calling finalize. So was the comment there wrong? What if other is a Series? Does this have an impact on the result?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this have an impact on the result?

In the overwhemingly-most-common case where there is no user-defined _metadata, no, this doesn't affect the result. Otherwise, it affects the result when other is a Series.

@jreback jreback added the Clean label Sep 24, 2019
@jreback
Copy link
Contributor

jreback commented Sep 24, 2019

any additional tests needed?

@jbrockmendel
Copy link
Member Author

any additional tests needed?

I'm inclined towards "no" because the behavior that is affected is stuff we don't particularly care about.

@TomAugspurger
Copy link
Contributor

Just to verify, we don't have any cases where we pass a DataFrame to Series.__finalize__ right?

On my disallow-duplicates I noticed some strange behavior with DataFrame's having a name column, since we did self.name = getattr(other, 'name', None), which tried to set Series.name to the name column in the DataFrame.

@jbrockmendel
Copy link
Member Author

Just to verify, we don't have any cases where we pass a DataFrame to Series.finalize right?

Not in this file, no.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 24, 2019 via email

@jreback jreback added this to the 1.0 milestone Sep 26, 2019
@jreback jreback merged commit 53ad101 into pandas-dev:master Sep 26, 2019
@jreback
Copy link
Contributor

jreback commented Sep 26, 2019

thanks!

@jbrockmendel jbrockmendel deleted the finalizer branch September 26, 2019 14:42
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
bongolegend pushed a commit to bongolegend/pandas that referenced this pull request Jan 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants