numpy / numpy/numpy

interp can not handle datetime64, while fix seems easy

Open
#14,941 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

01 - Enhancement component: numpy.datetime64 component: numpy.lib
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.