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

ENH: Add datatime64 support in np.interp #14990

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mproszewska
Copy link
Contributor

@mproszewska mproszewska commented Nov 27, 2019

ENH: Add support for types convertible to float64 in np.interp

Closes #14941

@eric-wieser
Copy link
Member

For other's reviewing - previously this raised TypeError: Cannot cast array data from dtype('<M8[D]') to dtype('float64') according to the rule 'safe'

yp = np.array([1, 3])
x = np.datetime64('2019-01-02')
assert_equal(np.interp(x, xp, yp), 2.)
assert_raises(TypeError, np.interp(1., xp, yp))
Copy link
Member

Choose a reason for hiding this comment

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

I was expecting this test to fail, but it seems to pass.. Any idea which line of your code causes the TypeError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should fail.

np.interp(1., xp, yp)

doesn't raise this error. It might be a problem with assert_raises and it's similar to #15008

But do we want to check if types in x and xp are the same? Maybe it's enough that both can be cast to np.float64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, it should have been

assert_raises(TypeError, np.interp, 1., xp, yp)

But again, is this a better approach?

@mproszewska
Copy link
Contributor Author

This PR would make np.interp support any type that can be converter to float64. In my opinion that's a better approach. Happy to receive any feedback..

Base automatically changed from master to main March 4, 2021 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Awaiting a code review
Development

Successfully merging this pull request may close these issues.

interp can not handle datetime64, while fix seems easy
2 participants