interp can not handle datetime64, while fix seems easy
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the np.interp entry point and reproduce the datetime64 failure using the example in this issue. Check how datetime64 arrays are currently cast and compare that behavior with the working float64 conversion. Done means the documented datetime64 example runs successfully with the expected interpolated value, with coverage for the relevant input types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100