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

CLN: use .view(i8) instead of .astype(i8) for datetimelike values #38535

Merged
merged 2 commits into from
Dec 19, 2020

Conversation

jbrockmendel
Copy link
Member

prelude to deprecating the astype behavior

@@ -252,7 +253,9 @@ def __init__(
raise ValueError(
"halflife must be a string or datetime.timedelta object"
)
self.times = np.asarray(times.astype(np.int64))
if isna(times).any():
raise ValueError("Cannot convert NaT values to integer")
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 add a test for this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

double-checked and you're right we dont have any. suggestions for what this might look like?

Copy link
Member

Choose a reason for hiding this comment

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

Something simple like

with pytest.raises(ValueError, match=...):
     Series(range(1)).ewm(com=0.1, times=to_datetime(['NaT'])))

works.

@jreback jreback added Clean Datetime Datetime data dtype labels Dec 17, 2020
@jreback
Copy link
Contributor

jreback commented Dec 17, 2020

any perf benefits?

@jbrockmendel
Copy link
Member Author

any perf benefits?

maybe some call overhead, but the existing astype call is already doing view under the hood (which is not great)

@jreback jreback added this to the 1.3 milestone Dec 19, 2020
@jreback jreback merged commit 9b58415 into pandas-dev:master Dec 19, 2020
@jbrockmendel jbrockmendel deleted the ref-astype_nansafe-ints branch December 19, 2020 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants