Skip to content

DOC: update the pandas.Series/DataFrame.interpolate docstring #20270

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6096,15 +6096,15 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
* 'pad': Fill in NaNs using existing values.
* 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'spline',
'barycentric', 'polynomial': Passed to
``scipy.interpolate.interp1d``. Both 'polynomial' and 'spline'
`scipy.interpolate.interp1d`. Both 'polynomial' and 'spline'
require that you also specify an `order` (int),
e.g. ``df.interpolate(method='polynomial', order=4)``.
These use the numerical values of the index.
* 'krogh', 'piecewise_polynomial', 'spline', 'pchip', 'akima':
Wrappers around the SciPy interpolation methods of similar
names. See `Notes`.
* 'from_derivatives': Refers to
``scipy.interpolate.BPoly.from_derivatives`` which
`scipy.interpolate.BPoly.from_derivatives` which
replaces 'piecewise_polynomial' interpolation method in
scipy 0.18.

Expand All @@ -6129,7 +6129,7 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
If limit is specified, consecutive NaNs will be filled with this
restriction.

* None: No fill restriction.
* ``None``: No fill restriction.
* 'inside': Only fill NaNs surrounded by valid values
(interpolate).
* 'outside': Only fill NaNs outside valid values (extrapolate).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add an example for 'outside'

Expand All @@ -6145,7 +6145,7 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
-------
Series or DataFrame
Returns the same object type as the caller, interpolated at
some or all `NaN` values
some or all ``NaN`` values

See Also
--------
Expand Down Expand Up @@ -6174,7 +6174,7 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,

Examples
--------
Filling in `NaN` in a :class:`~pandas.Series` via linear
Filling in ``NaN`` in a :class:`~pandas.Series` via linear
interpolation.

>>> s = pd.Series([0, 1, np.nan, 3])
Expand All @@ -6191,8 +6191,8 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
3 3.0
dtype: float64

Filling in `NaN` in a Series by padding, but filling at most two
consecutive `NaN` at a time.
Filling in ``NaN`` in a Series by padding, but filling at most two
consecutive ``NaN`` at a time.

>>> s = pd.Series([np.nan, "single_one", np.nan,
... "fill_two_more", np.nan, np.nan, np.nan,
Expand Down Expand Up @@ -6220,9 +6220,9 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
8 4.71
dtype: object

Filling in `NaN` in a Series via polynomial interpolation or splines:
Both `polynomial` and `spline` methods require that you also specify
an `order` (int).
Filling in ``NaN`` in a Series via polynomial interpolation or splines:
Both 'polynomial' and 'spline' methods require that you also specify
an ``order`` (int).
Copy link
Member

@WillAyd WillAyd Aug 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters should be single backticks - double is only for literals and code samples I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that double backticks is for code, including parts like a single variable None, an assignment foo=1... Single backticks is for things that you can refer (link) to, like a function, class, module... And for values just quotes.

For an argument, I'd consider it more code, that something you can link to. That's why I added double backticks. But it's very subtle, I'd be happy with any option (no quoting, single backticks, double backticks and quotes).

Does this make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep thanks. I think I've seen other instances where parameters are in single backticks but this is nuanced enough that it shouldn't hold up the PR - can be part of a larger conversation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a bullet point to #20298 to decide a standard for these cases. I think at the moment there is not much consistency.


>>> s = pd.Series([0, 2, np.nan, 8])
>>> s.interpolate(method='polynomial', order=2)
Expand All @@ -6235,9 +6235,9 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
Fill the DataFrame forward (that is, going down) along each column
using linear interpolation.

Note how the last entry in column `a` is interpolated differently,
Note how the last entry in column 'a' is interpolated differently,
because there is no entry after it to use for interpolation.
Note how the first entry in column `b` remains `NaN`, because there
Note how the first entry in column 'b' remains ``NaN``, because there
is no entry befofe it to use for interpolation.

>>> df = pd.DataFrame([(0.0, np.nan, -1.0, 1.0),
Expand Down