Skip to content
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

DOC: Add docstring for Extensionarray interpolate #59749

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Timestamp.resolution PR02" \
-i "pandas.Timestamp.tzinfo GL08" \
-i "pandas.Timestamp.year GL08" \
-i "pandas.api.extensions.ExtensionArray.interpolate PR01,SA01" \
-i "pandas.api.types.is_dict_like PR07,SA01" \
-i "pandas.api.types.is_extension_array_dtype SA01" \
-i "pandas.api.types.is_file_like PR07,SA01" \
Expand Down
78 changes: 76 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,74 @@ def interpolate(
**kwargs,
) -> Self:
"""
See DataFrame.interpolate.__doc__.
Fill NaN values using an interpolation method.

Parameters
----------
method : str, default 'linear'
Interpolation technique to use. One of:
* 'linear': Ignore the index and treat the values as equally spaced.
This is the only method supported on MultiIndexes.
* 'time': Works on daily and higher resolution data to interpolate
given length of interval.
* 'index', 'values': use the actual numerical values of the index.
* 'pad': Fill in NaNs using existing values.
* 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'barycentric',
'polynomial': Passed to scipy.interpolate.interp1d, whereas 'spline'
is passed to scipy.interpolate.UnivariateSpline. These methods use
the numerical values of the index.
Both 'polynomial' and 'spline' require that you also specify an
order (int), e.g. arr.interpolate(method='polynomial', order=5).
* 'krogh', 'piecewise_polynomial', 'spline', 'pchip', 'akima',
'cubicspline': Wrappers around the SciPy interpolation methods
of similar names. See Notes.
* 'from_derivatives': Refers to scipy.interpolate.BPoly.from_derivatives.
axis : int
Axis to interpolate along. For 1-dimensional data, use 0.
index : Index
Index to use for interpolation.
limit : int or None
Maximum number of consecutive NaNs to fill. Must be greater than 0.
limit_direction : {'forward', 'backward', 'both'}
Consecutive NaNs will be filled in this direction.
limit_area : {'inside', 'outside'} or None
If limit is specified, consecutive NaNs will be filled with this
restriction.
* None: No fill restriction.
* 'inside': Only fill NaNs surrounded by valid values (interpolate).
* 'outside': Only fill NaNs outside valid values (extrapolate).
copy : bool
If True, a copy of the object is returned with interpolated values.
**kwargs : optional
Keyword arguments to pass on to the interpolating function.

Returns
-------
ExtensionArray
An ExtensionArray with interpolated values.

See Also
--------
Series.interpolate : Interpolate values in a Series.
DataFrame.interpolate : Interpolate values in a DataFrame.

Notes
-----
- All parameters must be specified as keyword arguments.
- The 'krogh', 'piecewise_polynomial', 'spline', 'pchip' and 'akima'
methods are wrappers around the respective SciPy implementations of
similar names. These use the actual numerical values of the index.

Examples
--------
Interpolating values in a NumPy array:

>>> arr = pd.arrays.NumpyExtensionArray(np.array([0, 1, np.nan, 3]))
>>> arr.interpolate(
... method="linear",
... limit=3,
... limit_direction="forward",
... index=pd.Index([1, 2, 3, 4]),
... index=pd.Index(range(len(arr))),
... fill_value=1,
... copy=False,
... axis=0,
Expand All @@ -1017,6 +1075,22 @@ def interpolate(
<NumpyExtensionArray>
[0.0, 1.0, 2.0, 3.0]
Length: 4, dtype: float64

Interpolating values in a FloatingArray:

>>> arr = pd.array([1.0, pd.NA, 3.0, 4.0, pd.NA, 6.0], dtype="Float64")
>>> arr.interpolate(
... method="linear",
... axis=0,
... index=pd.Index(range(len(arr))),
... limit=None,
... limit_direction="both",
... limit_area=None,
... copy=True,
... )
<FloatingArray>
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
Length: 6, dtype: Float64
"""
# NB: we return type(self) even if copy=False
raise NotImplementedError(
Expand Down