Skip to content

DEPR: NDFrame.to_period, to_timestamp, tz_localize, tz_convert #52110

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

Open
jbrockmendel opened this issue Mar 21, 2023 · 4 comments
Open

DEPR: NDFrame.to_period, to_timestamp, tz_localize, tz_convert #52110

jbrockmendel opened this issue Mar 21, 2023 · 4 comments
Labels
API Design Datetime Datetime data dtype Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses Needs Discussion Requires discussion from core team before further action Period Period data type

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Mar 21, 2023

These are methods that operate on the index/columns, not the series/frame values. We could deprecate in favor of e.g. obj.set_axis(obj.index.to_timestamp(), axis=0)

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 21, 2023
@lithomas1 lithomas1 added Datetime Datetime data dtype Period Period data type Deprecate Functionality to remove in pandas Needs Discussion Requires discussion from core team before further action Index Related to the Index class or subclasses Timestamp pd.Timestamp and associated methods and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 22, 2023
@jbrockmendel jbrockmendel removed the Timestamp pd.Timestamp and associated methods label Mar 22, 2023
@topper-123
Copy link
Contributor

topper-123 commented Apr 5, 2023

#52023 was about adding a generic method for getting axes. Doing this + doing #52023 would IMO be much more flexible than the current situation and we wouldn’t need specific index methods on ndframes.

EDIT: changed "setting" to "getting".

@topper-123
Copy link
Contributor

I'm +1 on deprecating those methods. i can never remember which index methods are mirrored in the ndframe, so I always end up just doing

df = df.copy()  # if I don't want to keep the old frame
df.index = df.index.tz_localize(tz)

IMO a set_axis method would be nice if it could be used in a pipe. For that to work, the first argument should be either an indexlike or a callable, so something like piped_df.set_index(lambda x: x.tz_localize(tz), axis="index") and piped_df.set_index(pd.Index(...), axis="index") could both work.

We have a lot of index methods and only some will feature in the axis_ops namespace and it's not intuitive why those have been selected and others not. so it's same problem as beforehand for me. What about adding a set_index method and skipping axis_ops?

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Apr 26, 2023

We had a discussion related to this PR during the dev meeting on 4/26/23. Methods like NDFrame.first(), NDFrame.last(), NDFrame.between_time(), and NDFrame.filter() are really creating an NDFrame based on values in the index, and that it might be better to move those methods to be on Index, and then use .loc on the resulting index to get the result (which is most of these implementations do anyway).

I did a PR for filter() to create a new Index.filter() method that would give the index, but it didn't go anywhere.
#51370 The discussion we had was maybe we should be moving more of these methods out of NDFrame and maybe into the new axis_ops proposed here.

@jorisvandenbossche
Copy link
Member

I am fine with deprecating to_period and to_timestamp (and I don't think we necessarily need a new alternative like axis_ops for those, I don't think those are used that often), but personally I would prefer to keep tz_localize and tz_convert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Deprecate Functionality to remove in pandas Index Related to the Index class or subclasses Needs Discussion Requires discussion from core team before further action Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants