question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate minimal entries in interpolate.interp1d result in nan

See original GitHub issue

interpolate.interp1d returns nan in the following example for me (scipy version is 0.14.0):

In [7]: f = interpolate.interp1d([0, 0, 1], [0, 0, 1], kind='linear')
In [8]: f(0)
 /home/jmetzen/.anaconda/lib/python2.7/site-packages/scipy/interpolate/interpolate.py:445: RuntimeWarning: invalid value encountered in true_divide
 slope = (y_hi - y_lo) / (x_hi - x_lo)[:, None]
Out[8]: array(nan)

Everything works fine in the case without duplicates:

In [13]: f = interpolate.interp1d([0, 1], [0,  1], kind='linear')
In [14]: f(0)
Out[14]: array(0.0)

Duplicating any other entry besides the minimal one seems to be ok. I guess this is a bug?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
argriffingcommented, Dec 26, 2014

The docs say

See also
UnivariateSpline -- A more recent wrapper of the FITPACK routines.

Would it make sense to officially deprecate interp1d so that it raises a deprecation warning?

Edit: never mind, I see that interp1d clones a matlab function, so it will live forever.

0reactions
ev-brcommented, Aug 5, 2019

We won’t be deprecating interp1d any time soon it seems. Handling of duplicate values is also best left as is, cf. gh-9886. Looks like there’s not much to do here, thus closing. Thanks @jmetzen, all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does interp1d in scipy give a NaN when the first 2 values ...
Your problem is that you are trying to interpolate points that are outside the interval, this causes that scipy.interpolate.interp1d ...
Read more >
scipy.interpolate.interp1d — SciPy v1.9.3 Manual
Specifies the axis of y along which to interpolate. Interpolation defaults to the last axis of y. copybool, optional. If True, the class...
Read more >
Source code for cooltools.lib.numutils
[docs]def fill_na(arr, value=0, copy=True): """Replaces np.nan entries in an array ... interpolator = scipy.interpolate.interp1d( inds[~isnan], a[~isnan], ...
Read more >
mtweb.cs.ucl.ac.uk/mus/lib/python2.6/scipy-0.11.0-...
This class returns a function whose call method uses spline interpolation to ... kind='linear', copy=True, bounds_error=False, fill_value=np.nan): self.x, ...
Read more >
brainbox.processing.processing — IBL Library documentation
import numpy as np import pandas as pd from scipy import interpolate from ... See interp1d for possible values, defaults to np.nan :return:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found