Skip to content
1 change: 1 addition & 0 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.api.extensions.ExtensionArray.factorize \
pandas.api.extensions.ExtensionArray.fillna \
pandas.api.extensions.ExtensionArray.insert \
pandas.api.extensions.ExtensionArray.interpolate \
pandas.api.extensions.ExtensionArray.isin \
pandas.api.extensions.ExtensionArray.isna \
pandas.api.extensions.ExtensionArray.ravel \
Expand Down
1 change: 1 addition & 0 deletions doc/source/reference/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ objects.
api.extensions.ExtensionArray.factorize
api.extensions.ExtensionArray.fillna
api.extensions.ExtensionArray.insert
api.extensions.ExtensionArray.interpolate
api.extensions.ExtensionArray.isin
api.extensions.ExtensionArray.isna
api.extensions.ExtensionArray.ravel
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ Other enhancements
- :meth:`Series.str.join` now supports ``ArrowDtype(pa.string())`` (:issue:`53646`)
- :meth:`SeriesGroupby.agg` and :meth:`DataFrameGroupby.agg` now support passing in multiple functions for ``engine="numba"`` (:issue:`53486`)
- :meth:`SeriesGroupby.transform` and :meth:`DataFrameGroupby.transform` now support passing in a string as the function for ``engine="numba"`` (:issue:`53579`)
- Added :meth:`ExtensionArray.interpolate` used by :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` (:issue:`53659`)
- Added ``engine_kwargs`` parameter to :meth:`DataFrame.to_excel` (:issue:`53220`)
- Added a new parameter ``by_row`` to :meth:`Series.apply`. When set to ``False`` the supplied callables will always operate on the whole Series (:issue:`53400`).
- Groupby aggregations (such as :meth:`DataFrameGroupby.sum`) now can preserve the dtype of the input instead of casting to ``float64`` (:issue:`44952`)
- Improved error message when :meth:`DataFrameGroupBy.agg` failed (:issue:`52930`)
- Many read/to_* functions, such as :meth:`DataFrame.to_pickle` and :func:`read_csv`, support forwarding compression arguments to lzma.LZMAFile (:issue:`52979`)
- Performance improvement in :func:`concat` with homogeneous ``np.float64`` or ``np.float32`` dtypes (:issue:`52685`)
- Performance improvement in :meth:`DataFrame.filter` when ``items`` is given (:issue:`52941`)
-

.. ---------------------------------------------------------------------------
.. _whatsnew_210.notable_bug_fixes:
Expand Down
20 changes: 20 additions & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,26 @@ def closed(self) -> bool:

# Arguments for fillna()
FillnaOptions = Literal["backfill", "bfill", "ffill", "pad"]
InterpolateOptions = Literal[
"linear",
"time",
"index",
"values",
"nearest",
"zero",
"slinear",
"quadratic",
"cubic",
"barycentric",
"polynomial",
"krogh",
"piecewise_polynomial",
"spline",
"pchip",
"akima",
"cubicspline",
"from_derivatives",
]

# internals
Manager = Union[
Expand Down
26 changes: 26 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
AxisInt,
Dtype,
FillnaOptions,
InterpolateOptions,
NumpySorter,
NumpyValueArrayLike,
PositionalIndexer,
Expand All @@ -90,6 +91,8 @@
npt,
)

from pandas import Index

_extension_array_shared_docs: dict[str, str] = {}


Expand Down Expand Up @@ -118,6 +121,7 @@ class ExtensionArray:
fillna
equals
insert
interpolate
isin
isna
ravel
Expand Down Expand Up @@ -155,6 +159,7 @@ class ExtensionArray:
* take
* copy
* _concat_same_type
* interpolate

A default repr displaying the type, (truncated) data, length,
and dtype is provided. It can be customized or replaced by
Expand Down Expand Up @@ -753,6 +758,27 @@ def argmax(self, skipna: bool = True) -> int:
raise NotImplementedError
return nargminmax(self, "argmax")

def interpolate(
self,
*,
method: InterpolateOptions,
axis: int,
index: Index,
limit,
limit_direction,
limit_area,
fill_value,
copy: bool,
**kwargs,
) -> Self:
"""
See DataFrame.interpolate.__doc__.
"""
# NB: we return type(self) even if copy=False
raise NotImplementedError(
f"{type(self).__name__} does not implement interpolate"
)

def fillna(
self,
value: object | ArrayLike | None = None,
Expand Down
11 changes: 6 additions & 5 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
Dtype,
DtypeObj,
F,
InterpolateOptions,
NpDtype,
PositionalIndexer2D,
PositionalIndexerTuple,
Expand Down Expand Up @@ -2233,23 +2234,23 @@ def copy(self, order: str = "C") -> Self:
def interpolate(
self,
*,
method,
method: InterpolateOptions,
axis: int,
index: Index,
limit,
limit_direction,
limit_area,
inplace: bool,
copy: bool,
**kwargs,
) -> Self:
"""
See NDFrame.interpolate.__doc__.
"""
# NB: we return type(self) even if inplace=True
# NB: we return type(self) even if copy=False
if method != "linear":
raise NotImplementedError

if inplace:
if not copy:
out_data = self._ndarray
else:
out_data = self._ndarray.copy()
Expand All @@ -2264,7 +2265,7 @@ def interpolate(
limit_area=limit_area,
**kwargs,
)
if inplace:
if not copy:
return self
return type(self)._simple_new(out_data, dtype=self.dtype)

Expand Down
11 changes: 6 additions & 5 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
AxisInt,
Dtype,
FillnaOptions,
InterpolateOptions,
NpDtype,
Scalar,
Self,
Expand Down Expand Up @@ -261,20 +262,20 @@ def pad_or_backfill(
def interpolate(
self,
*,
method,
method: InterpolateOptions,
axis: int,
index: Index,
limit,
limit_direction,
limit_area,
inplace: bool,
copy: bool,
**kwargs,
) -> Self:
"""
See NDFrame.interpolate.__doc__.
"""
# NB: we return type(self) even if inplace=True
if inplace:
# NB: we return type(self) even if copy=False
if not copy:
out_data = self._ndarray
else:
out_data = self._ndarray.copy()
Expand All @@ -290,7 +291,7 @@ def interpolate(
limit_area=limit_area,
**kwargs,
)
if inplace:
if not copy:
return self
return type(self)._simple_new(out_data, dtype=self.dtype)

Expand Down
23 changes: 2 additions & 21 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
IgnoreRaise,
IndexKeyFunc,
IndexLabel,
InterpolateOptions,
IntervalClosedType,
JSONSerializable,
Level,
Expand Down Expand Up @@ -7753,27 +7754,7 @@ def replace(
@final
def interpolate(
self,
method: Literal[
"linear",
"time",
"index",
"values",
"pad",
"nearest",
"zero",
"slinear",
"quadratic",
"cubic",
"barycentric",
"polynomial",
"krogh",
"piecewise_polynomial",
"spline",
"pchip",
"akima",
"cubicspline",
"from_derivatives",
] = "linear",
method: InterpolateOptions = "linear",
*,
axis: Axis = 0,
limit: int | None = None,
Expand Down
Loading