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

ENH: NDFrame.axis_ops #52461

Closed
wants to merge 41 commits into from
Closed

Conversation

jbrockmendel
Copy link
Member

Refactor out NDFrame methods that operate only on axes into an obj.axis_ops namespace. I'd want to do this in conjunction with a deprecation of the methods themselves xref #52110

@jbrockmendel
Copy link
Member Author

@phofl updated to include more underscores


Let's reorder the levels of the index:

>>> df.reorder_levels(["diet", "class"])
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these example show the new usage of df.axis_ops.foo?

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Does axis_ops render in the API reference docs?

@mroeschke mroeschke added Refactor Internal refactoring of code Index Related to the Index class or subclasses labels May 24, 2023
@@ -190,6 +190,7 @@ Partial string indexing now matches on ``DateTimeIndex`` when part of a ``MultiI
On other levels

.. ipython:: python
:okwarning:
Copy link
Member

Choose a reason for hiding this comment

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

Could you just change this to use axis_ops.swaplevel?

Copy link
Member Author

Choose a reason for hiding this comment

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

i dont think we'd want to change this in the old doc

Copy link
Member

Choose a reason for hiding this comment

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

Okay could we use code block instead?

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Could you also ensure the API reference page advertises e.g. DataFrame.axis_ops.foo instead of DataFrame.foo?

@jbrockmendel
Copy link
Member Author

Could you also ensure the API reference page advertises e.g. DataFrame.axis_ops.foo instead of DataFrame.foo?

I'm not clear on how that works. For e.g. swaplevel would I remove the entry for Series.swaplevel in source/reference/series.rst? I could add Series.axis_ops in the same place but will adding Series.axis_ops.swap_level render?

@mroeschke
Copy link
Member

mroeschke commented Jul 18, 2023

I could add Series.axis_ops in the same place but will adding Series.axis_ops.swap_level render?

I think so. I think we have an autosummary template that renders our accessors (like Series.str.foo)

@jbrockmendel
Copy link
Member Author

An alternative: just deprecate tz_localize, tz_convert, to_timestamp, to_period and leave the others as-is

@mroeschke
Copy link
Member

Yeah actually that's a good point. if there's an index.foo() alternative might as well deprecate the DataFrame.foo() behavior

@jbrockmendel
Copy link
Member Author

Closing for lack of interest, will do individual deprecations in the subset of cases where that is feasible

@jbrockmendel jbrockmendel deleted the ref-axis_ops branch October 10, 2023 15:59
@jbrockmendel jbrockmendel restored the ref-axis_ops branch October 19, 2023 22:05
@jbrockmendel
Copy link
Member Author

Reopening, will merge main and push shortly.

@jbrockmendel jbrockmendel reopened this Oct 19, 2023
@jorisvandenbossche
Copy link
Member

FWIW, while I understand the reason for adding something like this, I would not be very enthusiastic about an axis_ops accessor (from a user design point of view, it feels rather awkward)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants