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

DEPR: datetimelike.astype(int) #38544

Merged
merged 8 commits into from Dec 23, 2020
Merged

Conversation

jbrockmendel
Copy link
Member

Sits on top of #38535

@jbrockmendel jbrockmendel changed the title DEPR: datetimelike.astype(int) 93d8b25 DEPR: datetimelike.astype(int) Dec 17, 2020
@jreback
Copy link
Contributor

jreback commented Dec 19, 2020

can you merge master

@jreback jreback added Deprecate Functionality to remove in pandas Dtype Conversions Unexpected or buggy dtype conversions labels Dec 19, 2020
@jreback jreback modified the milestones: 1.2.1, 1.3 Dec 19, 2020
@@ -142,7 +142,7 @@ Other API changes

Deprecations
~~~~~~~~~~~~

- Deprecated casting of datetimelike (``timedelta64[ns]``, ``datetime64[ns]``, ``Datetime64TZDtype``, ``PeriodDtype``) to integer dtypes, use ``values.view(...)`` instead (:issue:`38544`)
Copy link
Contributor

Choose a reason for hiding this comment

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

casting -> astype

Copy link
Member Author

Choose a reason for hiding this comment

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

will update

Copy link
Member Author

Choose a reason for hiding this comment

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

updated+green

@@ -48,15 +49,17 @@ def test_astype_conversion(self):
tm.assert_index_equal(result, expected)

idx = period_range("1990", "2009", freq="A", name="idx")
result = idx.astype("i8")
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

for a lot of these you can just change the test if you want to use view

Copy link
Member Author

Choose a reason for hiding this comment

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

changed one of these, the rest were specifically targeting astype and not worth mucking with

@jreback
Copy link
Contributor

jreback commented Dec 23, 2020

do we have sufficient .view tests on Index ?

@jbrockmendel
Copy link
Member Author

do we have sufficient .view tests on Index ?

looks decent, yah

@jreback jreback merged commit 7db5f57 into pandas-dev:master Dec 23, 2020
@jbrockmendel jbrockmendel deleted the depr-astype-i8 branch December 23, 2020 19:26
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Sep 16, 2021

I ran into this case of datetime->integer casting while exploring our casting rules (#22384). @jbrockmendel do you remember the rationale for deprecating this casting? It's not really clear to me why we would in the future disallow datetimelike->integer casting.

This PR doesn't seem to give much reasoning, and the referenced issue is about the bitwidth / sign being ignored, but not sure deprecating altogether is necessarily the fix for that (the bitwidth being ignored also applies for integer->integer casting, which we didn't deprecate).

@jbrockmendel
Copy link
Member Author

#22384 (comment)

We currently raise a warning about the dt64 -> int64 that this will raise instead in the future and to use view instead. Do you know what the rationale was for this deprecation?

The idea is that 'astype' in general means something like 'the same information but in a different format' and that doesn't make sense with i8 <-> M8

@jorisvandenbossche
Copy link
Member

Whoops, sorry, I totally forgot I already asked / you answered in the other thread .. :) Will continue there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datetimelike index / arrays ignore integer sign and size in astype
3 participants