Skip to content

DOC: fix docstring for DataFrame.interpolate #7553

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

Merged
merged 1 commit into from
Jul 7, 2014
Merged

DOC: fix docstring for DataFrame.interpolate #7553

merged 1 commit into from
Jul 7, 2014

Conversation

jdreaver
Copy link

In the old docstring, 'index' is listed as a valid value for the method kwarg for DataFrame.interpolate. It looks like a typo, because there was no comma after 'index', and the explanation for 'index' corresponded to 'values'. Furthermore, it appears 'index' is not a valid value for method:

In [67]: df = pd.DataFrame([[1], [2], [np.nan], [3]], index=[0, 0.7, 1.1, 4])

In [68]: df
Out[68]: 
      0
0.0   1
0.7   2
1.1 NaN
4.0   3

In [69]: df.interpolate(method="index")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-4cef75cee92e> in <module>()
----> 1 df.interpolate(method="index")

/home/david/miniconda3/envs/frackoptima/lib/python3.4/site-packages/pandas/core/generic.py in interp
olate(self, method, axis, limit, inplace, downcast, **kwargs)                                      
   2580                                           inplace=inplace,
   2581                                           downcast=downcast,
-> 2582                                           **kwargs)
   2583         if inplace:
   2584             if axis == 1:

/home/david/miniconda3/envs/frackoptima/lib/python3.4/site-packages/pandas/core/internals.py in inte
rpolate(self, **kwargs)                                                                            
   2195 
   2196     def interpolate(self, **kwargs):
-> 2197         return self.apply('interpolate', **kwargs)
   2198 
   2199     def shift(self, **kwargs):

/home/david/miniconda3/envs/frackoptima/lib/python3.4/site-packages/pandas/core/internals.py in appl
y(self, f, axes, filter, do_integrity_check, **kwargs)                                             
   2162                                                  copy=align_copy)
   2163 
-> 2164             applied = getattr(b, f)(**kwargs)
   2165 
   2166             if isinstance(applied, list):

/home/david/miniconda3/envs/frackoptima/lib/python3.4/site-packages/pandas/core/internals.py in inte
rpolate(self, method, axis, index, values, inplace, limit, fill_value, coerce, downcast, **kwargs) 
    667                                      **kwargs)
    668 
--> 669         raise ValueError("invalid method '{0}' to interpolate.".format(method))
    670 
    671     def _interpolate_with_fill(self, method='pad', axis=0, inplace=False,

ValueError: invalid method 'index' to interpolate.

In [70]: df.interpolate(method="values")
Out[70]: 
            0
0.0  1.000000
0.7  2.000000
1.1  2.121212
4.0  3.000000

@jreback
Copy link
Contributor

jreback commented Jun 23, 2014

hmm.... @TomAugspurger ?

@TomAugspurger
Copy link
Contributor

I think 'index' and 'values' are supposed to be synonyms: #4915 (comment)

values was the old one, but 'index' makes more sense after that PR.

@jdreaver want to adjust your PR to do this? Just need to add 'index' to _clean_interp_method and change to if method in ['linear', 'time', 'values', 'index']: in interpolate_1d in core/common.py.

I can do a PR if need be, but my wi-fi has been spotty :(

@jreback jreback added this to the 0.14.1 milestone Jun 24, 2014
@jdreaver
Copy link
Author

That makes sense. Should I remove 'values' from the docstring for DataFrame.interpolate() entirely, replacing it with 'index'? Or should I add 'index' as an argument to method and change the relevant docstring line to 'index', 'values': use the actual numerical values of the index?

@jdreaver
Copy link
Author

I went ahead and added 'index' as a synonym. I can remove 'values' from the docstring too if you want. Just tell me.

@jreback
Copy link
Contributor

jreback commented Jun 24, 2014

they index is their for compat as that was the old method iirc

@jreback
Copy link
Contributor

jreback commented Jun 26, 2014

@TomAugspurger what is index supposed to map to? any tests for this?

@jreback
Copy link
Contributor

jreback commented Jul 1, 2014

@jdreaver can you add some tests for this ?

@jdreaver
Copy link
Author

jdreaver commented Jul 2, 2014

@jreback, I'll get around to it in the next couple days.

@jreback
Copy link
Contributor

jreback commented Jul 6, 2014

@TomAugspurger what's the status here?

@TomAugspurger
Copy link
Contributor

I think just waiting on a test that @jdreaver's fix is correct. The code looks fine, but it'd be nice to have a test.

@jdreaver
Copy link
Author

jdreaver commented Jul 6, 2014

I guess I didn't get around to it... I'll do it today in the next few hours.

@jdreaver
Copy link
Author

jdreaver commented Jul 6, 2014

I found the test where method='values' was tested, and I added a few lines to check that the output of 'values' and 'index' is the same. If travis passes, I think the pull request is complete.

@jreback
Copy link
Contributor

jreback commented Jul 6, 2014

gr8 pls ping in green

jreback added a commit that referenced this pull request Jul 7, 2014
DOC: fix docstring for DataFrame.interpolate
@jreback jreback merged commit 4c5ac6a into pandas-dev:master Jul 7, 2014
@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

@jdreaver thanks!

@jdreaver
Copy link
Author

jdreaver commented Jul 7, 2014

No problem! Sorry for forgetting about writing those tests!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Docs Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants