Skip to content

Commit 5ef4eba

Browse files
committed
all tests working
1 parent 6be51cb commit 5ef4eba

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pandas/core/generic.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6881,30 +6881,34 @@ def interpolate(
68816881
inplace = validate_bool_kwarg(inplace, "inplace")
68826882

68836883
axis = self._get_axis_number(axis)
6884+
index = self._get_axis(axis)
68846885

6885-
if axis == 0:
6886-
df = self
6887-
else:
6888-
df = self.T
6889-
6890-
if isinstance(df.index, MultiIndex) and method != "linear":
6886+
if isinstance(self.index, MultiIndex) and method != "linear":
68916887
raise ValueError(
68926888
"Only `method=linear` interpolation is supported on MultiIndexes."
68936889
)
68946890

6895-
if df.ndim == 2 and np.all(df.dtypes == np.dtype(object)):
6891+
if self.ndim == 2 and np.all(self.dtypes == np.dtype(object)):
68966892
raise TypeError(
68976893
"Cannot interpolate with all object-dtype columns "
68986894
"in the DataFrame. Try setting at least one "
68996895
"column to a numeric dtype."
69006896
)
69016897

6898+
6899+
if method in ['backfill', 'bfill', 'pad', 'ffill']:
6900+
return self.fillna(method=method, axis=axis, inplace=inplace, limit=limit, downcast=downcast)
69026901
# create/use the index
6902+
6903+
if axis==0:
6904+
df = self
6905+
else:
6906+
df = self.T
6907+
69036908
if method == "linear":
69046909
# prior default
69056910
index = np.arange(len(df.index))
69066911
else:
6907-
index = df.index
69086912
methods = {"index", "values", "nearest", "time"}
69096913
is_numeric_or_datetime = (
69106914
is_numeric_dtype(index)

pandas/tests/frame/methods/test_interpolate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ def test_interp_leading_nans(self, check_scipy):
202202
result = df.interpolate(method="polynomial", order=1)
203203
tm.assert_frame_equal(result, expected)
204204

205-
def test_interp_raise_on_only_mixed(self):
205+
@pytest.mark.parametrize('axis', [0, 1])
206+
def test_interp_raise_on_only_mixed(self, axis):
206207
df = DataFrame(
207208
{
208209
"A": [1, 2, np.nan, 4],
@@ -213,7 +214,7 @@ def test_interp_raise_on_only_mixed(self):
213214
}
214215
)
215216
with pytest.raises(TypeError):
216-
df.interpolate(axis=1)
217+
df.astype('object').interpolate(axis=axis)
217218

218219
def test_interp_raise_on_all_object_dtype(self):
219220
# GH 22985
@@ -284,3 +285,4 @@ def test_interp_time_inplace_axis(self, axis):
284285
result = expected.interpolate(axis=0, method="time")
285286
expected.interpolate(axis=0, method="time", inplace=True)
286287
tm.assert_frame_equal(result, expected)
288+

0 commit comments

Comments
 (0)