Skip to content

API/TST: Call __finalize__ in more places #33379

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 10 commits into from
Apr 10, 2020

Conversation

TomAugspurger
Copy link
Contributor

@TomAugspurger TomAugspurger commented Apr 7, 2020

Progress towards #28283. This
adds tests that ensures NDFrame.__finalize__ is called in more places.
Thus far I've added tests for anything that meets the following rule:

Pandas calls NDFrame.__finalize__ on any NDFrame method that returns
another NDFrame.

I think that given the generality of __finalize__, making any kind of
list of which methods should call it is going to be somewhat arbitrary.
That rule errs on the side of calling it too often, which I think is my
preference.

For reviewers I think the two most helpful pieces would be

  1. Do you agree with the general rule of NDFrame -> NDFrame should call __finalize__?
  2. A spot check on the tests I've added

If you don't agree with the general rule, then we'll need to go through method by method and determine whether that method should call __finalize__.

Once we have agreement that the tests I've added accurately reflect the desired outcome, this can be merged and we can fix xfails in smaller batches.

Progress towards pandas-dev#28283. This
adds tests that ensures `NDFrame.__finalize__` is called in more places.
Thus far I've added tests for anything that meets the following rule:

> Pandas calls `NDFrame.__finalize__` on any NDFrame method that returns
> another NDFrame.

I think that given the generality of `__finalize__`, making any kind of
list of which methods should call it is going to be somewhat arbitrary.
That rule errs on the side of calling it too often, which I think is my
preference.
@TomAugspurger TomAugspurger added API Design metadata _metadata, .attrs labels Apr 7, 2020
@TomAugspurger TomAugspurger added this to the 1.1 milestone Apr 8, 2020
@TomAugspurger
Copy link
Contributor Author

CI has finished here, just hasn't updated on the UI.

On the call yesterday, people generally seemed OK with the rule that methods returning NDFrames should call __finalize__.

Does anyone have issues with the structure of the finalize test (parametrize over constructor, constructor args, and method)? Or are we OK to move ahead here?

If so, I'll start to work on the xfails (methods that don't yet call __finalize__)

@jreback jreback merged commit 47de449 into pandas-dev:master Apr 10, 2020
@jreback
Copy link
Contributor

jreback commented Apr 10, 2020

nice work @TomAugspurger

Comment on lines +575 to +576
if annotate in {"left", "both"} and not isinstance(right, int):
right.attrs = {"a": 1}
Copy link
Member

@MarcoGorelli MarcoGorelli Nov 27, 2022

Choose a reason for hiding this comment

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

Hi @TomAugspurger - I don't suppose you remember, but was this meant to be

    if annotate in {"right", "both"} and not isinstance(right, int):
        right.attrs = {"a": 1}

?

EDIT so sorry, just noticed you'd confirmed this in #34373 (comment) . Please ignore my comment, sorry for the noise

@TomAugspurger TomAugspurger deleted the finalize-method-more-tests branch November 27, 2022 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design metadata _metadata, .attrs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants