Skip to content

DEPR: undo deprecation of astype(int64) for datetimelike values #45449

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 2 commits into from
Jan 20, 2022

Conversation

jorisvandenbossche
Copy link
Member

Closes #45034

@@ -430,14 +430,6 @@ def astype(self, dtype, copy: bool = True):
elif is_integer_dtype(dtype):
# we deliberately ignore int32 vs. int64 here.
# See https://github.com/pandas-dev/pandas/issues/24381 for more.
Copy link
Member

Choose a reason for hiding this comment

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

im OK with un-deprecating for the time being for i8. any objection to maintaining the deprecation for integer dtypes other than i8?

Copy link
Member Author

Choose a reason for hiding this comment

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

Other integer dtypes should IMO certainly use astype instead of view? (eg view(int32) doesn't make much sense since the original dtype is 64-bit)

Copy link
Member

Choose a reason for hiding this comment

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

I'm saying if the user does arr.astype(np.uint32) it doesn't make sense to give them arr.view(np.int64). i.e. we should keep the deprecation for dtypes other than np.int64.

Copy link
Member Author

Choose a reason for hiding this comment

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

And what I say is that it makes even less sense to ask them to do .view(np.int32) instead of giving them .view(np.int64) ;) (which will actually raise).

I understand that we are ignoring the bit-width here, and that is something we should fix. But I think that is unrelated to the "use view instead" deprecation (I also don't know if that is something we should deprecate first, or simply change).

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, we might be ignoring bit-width here, but that gets catched elsewhere. Because astyping to something else as int64/uint64 actually already raises an error at the moment (see also the table in #45034 (comment))

At least, that gets catched on the Series level. As you mentioned in that issue, the cast is allowed (bit width is ignored) at the array level.

Copy link
Member

Choose a reason for hiding this comment

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

And what I say is that it makes even less sense to ask them to do .view(np.int32) instead of giving them .view(np.int64) ;) (which will actually raise).

huh? If a user does dta.astype(np.uint32) im not advocating returning dta.view(np.int32), im advocating raising (or at least deprecating now and raising in the future).

Actually, we might be ignoring bit-width here, but that gets catched elsewhere. Because astyping to something else as int64/uint64 actually already raises an error at the moment (see also the table in #45034 (comment))

Yah we should try to handle these all symmetrically.

Copy link
Member Author

Choose a reason for hiding this comment

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

huh? If a user does dta.astype(np.uint32) im not advocating returning dta.view(np.int32), im advocating raising (or at least deprecating now and raising in the future).

I know that you are not advocating for that, but is is what the current deprecation warning implies the user to do (as is says to use view instead of astype).
You asked to "maintain the deprecation" for those cases, and what I am trying to say is that we should indeed fix those cases (in some way, with a different deprecation or breaking change (depending on the future behaviour), to be discussed), but IMO not by maintaining the current deprecation.

@jreback
Copy link
Contributor

jreback commented Jan 18, 2022

ok so going to back to using .astype here rather than .view, ok with that.

@jreback
Copy link
Contributor

jreback commented Jan 19, 2022

ok this is fine. @jorisvandenbossche @jbrockmendel ok here?

@jbrockmendel
Copy link
Member

sure, can merge this for 1.4 and can hammer out better solution for 1.5

@jreback
Copy link
Contributor

jreback commented Jan 20, 2022

thanks @jorisvandenbossche

@jreback
Copy link
Contributor

jreback commented Jan 20, 2022

@meeseeksdev backport 1.4.x

@lumberbot-app

This comment has been minimized.

@lumberbot-app

This comment has been minimized.

@jreback
Copy link
Contributor

jreback commented Jan 20, 2022

@jorisvandenbossche if you'd push a manual backport here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Astype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: allow casting datetime64 to int64?
4 participants