Skip to content

Commit 7a5d186

Browse files
Backport PR #35543: REGR: Fix interpolation on empty dataframe (#35764)
Co-authored-by: sanderland <[email protected]>
1 parent 56e95ad commit 7a5d186

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

doc/source/whatsnew/v1.1.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Fixed regressions
1919
- Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`)
2020
- Fixed regression where :func:`pandas.testing.assert_series_equal` would raise an error when non-numeric dtypes were passed with ``check_exact=True`` (:issue:`35446`)
2121
- Fixed regression in :class:`pandas.core.groupby.RollingGroupby` where column selection was ignored (:issue:`35486`)
22+
- Fixed regression where :meth:`DataFrame.interpolate` would raise a ``TypeError`` when the :class:`DataFrame` was empty (:issue:`35598`).
2223
- Fixed regression in :meth:`DataFrame.shift` with ``axis=1`` and heterogeneous dtypes (:issue:`35488`)
2324
- Fixed regression in :meth:`DataFrame.diff` with read-only data (:issue:`35559`)
2425
- Fixed regression in ``.groupby(..).rolling(..)`` where a segfault would occur with ``center=True`` and an odd number of values (:issue:`35552`)

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -6799,6 +6799,9 @@ def interpolate(
67996799

68006800
obj = self.T if should_transpose else self
68016801

6802+
if obj.empty:
6803+
return self
6804+
68026805
if method not in fillna_methods:
68036806
axis = self._info_axis_number
68046807

pandas/tests/frame/methods/test_interpolate.py

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def test_interp_basic(self):
3434
expected.loc[5, "B"] = 9
3535
tm.assert_frame_equal(result, expected)
3636

37+
def test_interp_empty(self):
38+
# https://github.com/pandas-dev/pandas/issues/35598
39+
df = DataFrame()
40+
result = df.interpolate()
41+
expected = df
42+
tm.assert_frame_equal(result, expected)
43+
3744
def test_interp_bad_method(self):
3845
df = DataFrame(
3946
{

0 commit comments

Comments
 (0)