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

interp can not handle datetime64, while fix seems easy #14941

Open
mbakker7 opened this issue Nov 19, 2019 · 2 comments · May be fixed by #14990
Open

interp can not handle datetime64, while fix seems easy #14941

mbakker7 opened this issue Nov 19, 2019 · 2 comments · May be fixed by #14990

Comments

@mbakker7
Copy link

The interp function can not handle datetime64 dtypes (docs are not explicit about this; they state that x and xp should be values). Error message is that array cannot be cast to dtype('float64') according to the rule 'safe'. But conversion seems easy.

Reproducing code example:

import numpy as np
d1 = np.datetime64('2019-01-01')
d2 = np.datetime64('2019-01-03')
xp = np.array([d1, d2])
yp = np.array([1, 3])
x = np.datetime64('2019-01-02')
np.interp(x, xp, yp)  # produces error

while the following works fine

np.interp(x.astype('float64'), xp.astype('float64'), yp)

So why is that not done in the interp function?

@madphysicist
Copy link
Contributor

If I'm not mistaken, np.ndarray.astype always makes a copy, while np.asfarray (with the appropriate flags) only makes one as necessary, so might be a better choice.

@seberg
Copy link
Member

seberg commented Nov 19, 2019

Well .astype(..., copy=False) also exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants