Skip to content

Commit de00994

Browse files
hkennyvrhshadrach
authored andcommitted
BUG, TST, DOC: fix core.missing._akima_interpolate will raise AttributeError (pandas-dev#33784)
1 parent 4718def commit de00994

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ Missing
574574
- Calling :meth:`fillna` on an empty Series now correctly returns a shallow copied object. The behaviour is now consistent with :class:`Index`, :class:`DataFrame` and a non-empty :class:`Series` (:issue:`32543`).
575575
- Bug in :meth:`replace` when argument ``to_replace`` is of type dict/list and is used on a :class:`Series` containing ``<NA>`` was raising a ``TypeError``. The method now handles this by ignoring ``<NA>`` values when doing the comparison for the replacement (:issue:`32621`)
576576
- Bug in :meth:`~Series.any` and :meth:`~Series.all` incorrectly returning ``<NA>`` for all ``False`` or all ``True`` values using the nulllable boolean dtype and with ``skipna=False`` (:issue:`33253`)
577+
- Clarified documentation on interpolate with method =akima. The ``der`` parameter must be scalar or None (:issue:`33426`)
577578

578579
MultiIndex
579580
^^^^^^^^^^

pandas/core/missing.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,9 @@ def _akima_interpolate(xi, yi, x, der=0, axis=0):
445445
A 1-D array of real values. `yi`'s length along the interpolation
446446
axis must be equal to the length of `xi`. If N-D array, use axis
447447
parameter to select correct axis.
448-
x : scalar or array_like of length M.
449-
der : int or list, optional
448+
x : scalar or array_like
449+
Of length M.
450+
der : int, optional
450451
How many derivatives to extract; None for all potentially
451452
nonzero derivatives (that is a number equal to the number
452453
of points), or a list of derivatives to extract. This number
@@ -468,12 +469,7 @@ def _akima_interpolate(xi, yi, x, der=0, axis=0):
468469

469470
P = interpolate.Akima1DInterpolator(xi, yi, axis=axis)
470471

471-
if der == 0:
472-
return P(x)
473-
elif interpolate._isscalar(der):
474-
return P(x, der=der)
475-
else:
476-
return [P(x, nu) for nu in der]
472+
return P(x, nu=der)
477473

478474

479475
def _cubicspline_interpolate(xi, yi, x, axis=0, bc_type="not-a-knot", extrapolate=None):

pandas/tests/series/methods/test_interpolate.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,28 @@ def test_interpolate_akima(self):
133133

134134
ser = Series([10, 11, 12, 13])
135135

136+
# interpolate at new_index where `der` is zero
136137
expected = Series(
137138
[11.00, 11.25, 11.50, 11.75, 12.00, 12.25, 12.50, 12.75, 13.00],
138139
index=Index([1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]),
139140
)
140-
# interpolate at new_index
141141
new_index = ser.index.union(Index([1.25, 1.5, 1.75, 2.25, 2.5, 2.75])).astype(
142142
float
143143
)
144144
interp_s = ser.reindex(new_index).interpolate(method="akima")
145145
tm.assert_series_equal(interp_s[1:3], expected)
146146

147+
# interpolate at new_index where `der` is a non-zero int
148+
expected = Series(
149+
[11.0, 1.0, 1.0, 1.0, 12.0, 1.0, 1.0, 1.0, 13.0],
150+
index=Index([1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]),
151+
)
152+
new_index = ser.index.union(Index([1.25, 1.5, 1.75, 2.25, 2.5, 2.75])).astype(
153+
float
154+
)
155+
interp_s = ser.reindex(new_index).interpolate(method="akima", der=1)
156+
tm.assert_series_equal(interp_s[1:3], expected)
157+
147158
@td.skip_if_no_scipy
148159
def test_interpolate_piecewise_polynomial(self):
149160
ser = Series([10, 11, 12, 13])

0 commit comments

Comments
 (0)