Skip to content
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

API: avoid passing Manager to subclass __init__ #57553

Merged
merged 7 commits into from
Mar 26, 2024

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Feb 21, 2024

Many subclasses have __init__ methods that call super().__init__, which in the relevant cases with a Manager object is deprecated. The solution in this PR is to construct the pd.DataFrame/Series and pass that to the subclass's _constructor.

This removes _sliced_from_mgr and _expanddim_from_mgr, as they are not really necessary, simplifying things a bit. Also makes _from_mgr @final. Can separate these simplifications into their own PR on request. xref #56681.

For subclasses that currently have special handling for Manager objects in their __init__, they will need to move that special handling to the appropriate _constructor(_foo)?_from_mgr method. The only package I'm aware of that does this is geopandas, so this includes a shim special-casing GeoDataFrame intended to maintain the current behavior until they have time to move that logic. cc @jorisvandenbossche ATM the shim is only in _constructor_from_mgr, pls advise on whether something analogous is needed in constructor_sliced_from_mgr and _constructor_expanddim_from_mgr.

# this check is slightly faster, benefiting the most-common case.
return df

elif type(self).__name__ == "GeoDataFrame":
Copy link
Member

Choose a reason for hiding this comment

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

Worth having a test for this in test_downstream.py? geopandas is installed in the CI

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 (also should add a test for#57032). Will wait until Joris weighs in

Copy link
Member Author

Choose a reason for hiding this comment

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

im having trouble writing a meaningful test for this cc @jorisvandenbossche

Copy link
Member

Choose a reason for hiding this comment

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

GeoPandas is already overriding _constructor_from_mgr, so normally this shouldn't be needed.

(will try to take a closer look one of the coming days!)

@mroeschke mroeschke added Internals Related to non-user accessible pandas implementation Constructors Series/DataFrame/Index/pd.array Constructors labels Feb 28, 2024
@jbrockmendel jbrockmendel added this to the 2.2.2 milestone Mar 12, 2024
@phofl phofl merged commit 805dbde into pandas-dev:main Mar 26, 2024
46 checks passed
@phofl
Copy link
Member

phofl commented Mar 26, 2024

thx @jbrockmendel

Copy link

lumberbot-app bot commented Mar 26, 2024

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 2.2.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 805dbde3651fa4f7c30d5c9c247f723dceb7dfde
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #57553: API: avoid passing Manager to subclass __init__'
  1. Push to a named branch:
git push YOURFORK 2.2.x:auto-backport-of-pr-57553-on-2.2.x
  1. Create a PR against branch 2.2.x, I would have named this PR:

"Backport PR #57553 on branch 2.2.x (API: avoid passing Manager to subclass init)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

jbrockmendel added a commit to jbrockmendel/pandas that referenced this pull request Mar 26, 2024
jbrockmendel added a commit to jbrockmendel/pandas that referenced this pull request Mar 29, 2024
mroeschke pushed a commit that referenced this pull request Mar 29, 2024
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Mar 29, 2024
mroeschke pushed a commit that referenced this pull request Apr 1, 2024
…class init) (#58008)

* Backport PR #57553: API: avoid passing Manager to subclass __init__

* whatsnew, type ignores

* merge 2.2.2 file from main

* rebase on 2.2.x whatsnew
lithomas1 pushed a commit that referenced this pull request Apr 1, 2024
…58080)

Backport PR #58075: DOC: whatsnew note for #57553

Co-authored-by: jbrockmendel <jbrockmendel@gmail.com>
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DeprecationWarning shown for internal operations on subclassed Series and DataFrame
5 participants