Skip to content

series.interpolate() corner cases #3674

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

Closed
lodagro opened this issue May 21, 2013 · 4 comments · Fixed by #3840
Closed

series.interpolate() corner cases #3674

lodagro opened this issue May 21, 2013 · 4 comments · Fixed by #3840
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@lodagro
Copy link
Contributor

lodagro commented May 21, 2013

from the pydata mailing list

I've been using Series.interpolate(), and have noticed that, while it
leaves NaN entries alone if they precede a non-null value, it blows up if
there are no non-null entries. Wouldn't it make more sense just to leave
completely null series alone (so the user doesn't have to manually check
for this case)? Here's an example:

  1. This one works:
S1 = Series([np.nan, 2.0])
print S1.interpolate()

-------

0   NaN
1     2
dtype: float64
  1. This one blows up:
S2 = Series([np.nan, np.nan])
print S2.interpolate()

ValueError                                Traceback (most recent call last)
<ipython-input-49-620b22122e43> in <module>()
      3
      4 S2 = Series([np.nan, np.nan])
----> 5 print S2.interpolate()

/RHS/packages/anaconda/pandas/pandas/core/series.pyc in interpolate(self,
method)
   3191         result = values.copy()
   3192         result[firstIndex:][invalid] = np.interp(inds[invalid],
inds[valid],
-> 3193
values[firstIndex:][valid])
   3194
   3195         return Series(result, index=self.index, name=self.name)

/Users/stanton/anaconda/lib/python2.7/site-packages/numpy/lib/function_base
.pyc in interp(x, xp, fp, left, right)
   1067         return compiled_interp([x], xp, fp, left, right).item()
   1068     else:
-> 1069         return compiled_interp(x, xp, fp, left, right)
   1070
   1071

ValueError: array of sample points is empty
  1. empty series (not mentioned in the original post)
In [38]: pd.Series([]).interpolate()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-38-012633a78523> in <module>()
----> 1 pd.Series([]).interpolate()

.../pandas/core/series.pyc in interpolate(self, method)
   3184         valid = -invalid
   3185 
-> 3186         firstIndex = valid.argmax()
   3187         valid = valid[firstIndex:]
   3188         invalid = invalid[firstIndex:]

ValueError: attempt to get argmax/argmin of an empty sequence
@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

@lodagro want to do a PR for this?

@lodagro
Copy link
Contributor Author

lodagro commented Jun 6, 2013

@jreback how can i refuse :-) ... probably not too much work, throw in a check somewhere for no NaN data. It won`t be in the next days though. btw are you and @y-p on pandas payroll? Your contribution is just crazy.

@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

hahah....just for fun!

thanks

lodagro added a commit to lodagro/pandas that referenced this issue Jun 10, 2013
jreback added a commit that referenced this issue Jun 13, 2013
BUG: fix Series.interpolate() corner cases, close #3674
@jreback
Copy link
Contributor

jreback commented Jun 13, 2013

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants