From a2816ca972d94410f8c6defb8acf2798edc39e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Sun, 2 Feb 2020 10:41:57 +0100 Subject: [PATCH 1/4] TST: add regression tests for fixed issue (#25190) Make sure that DataFrame.interpolate allows setting having "columns" or "index" as the axis argument. --- pandas/tests/frame/test_missing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index ae0516dd29a1f..7263c9335f139 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -983,3 +983,11 @@ def test_interp_time_inplace_axis(self, axis): result = expected.interpolate(axis=0, method="time") expected.interpolate(axis=0, method="time", inplace=True) tm.assert_frame_equal(result, expected) + + def test_interp_string_axis(self): + # GH 25190 + x = np.linspace(0, 100, 1000) + y = np.sin(x) + df = pd.DataFrame(data=np.tile(y, (10, 1)), index=np.arange(10), columns=x) + df.reindex(columns=x * 1.005).interpolate(method="linear", axis="columns") + df.reindex(columns=x * 1.005).interpolate(method="linear", axis="index") From e80d8b2ffceecfea2a8ed6d406462fdd3669eca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Sun, 2 Feb 2020 10:47:39 +0100 Subject: [PATCH 2/4] DOC: add whatsnew entry for bug fix (#25190) --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 40abb8f83de2f..c062cdee92145 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -158,6 +158,7 @@ Indexing - Bug in :meth:`PeriodIndex.is_monotonic` incorrectly returning ``True`` when containing leading ``NaT`` entries (:issue:`31437`) - Bug in :meth:`DatetimeIndex.get_loc` raising ``KeyError`` with converted-integer key instead of the user-passed key (:issue:`31425`) - Bug in :meth:`Series.xs` incorrectly returning ``Timestamp`` instead of ``datetime64`` in some object-dtype cases (:issue:`31630`) +- Bug in :meth:`DataFrame.interpolate` raising ``UnboundLocalError`` when specifying the ``axis`` with a string (:issue:`25190`) Missing ^^^^^^^ From fce6d16996021f80fc5029cd65979820645033d3 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 12 May 2020 13:08:04 +0100 Subject: [PATCH 3/4] update test --- pandas/tests/frame/methods/test_interpolate.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index aac242209e4a6..291a46cf03216 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -285,10 +285,14 @@ def test_interp_time_inplace_axis(self, axis): expected.interpolate(axis=0, method="time", inplace=True) tm.assert_frame_equal(result, expected) - def test_interp_string_axis(self): - # GH 25190 + @pytest.mark.parametrize("axis_name, axis_number", [("index", 0), ("columns", 1)]) + def test_interp_string_axis(self, axis_name, axis_number): + # https://github.com/pandas-dev/pandas/issues/25190 x = np.linspace(0, 100, 1000) y = np.sin(x) - df = DataFrame(data=np.tile(y, (10, 1)), index=np.arange(10), columns=x) - df.reindex(columns=x * 1.005).interpolate(method="linear", axis="columns") - df.reindex(columns=x * 1.005).interpolate(method="linear", axis="index") + df = DataFrame( + data=np.tile(y, (10, 1)), index=np.arange(10), columns=x + ).reindex(columns=x * 1.005) + result = df.interpolate(method="linear", axis=axis_name) + expected = df.interpolate(method="linear", axis=axis_number) + tm.assert_frame_equal(result, expected) From 1c81c9fec3a19fda18301cf4e60cdf5ec2038935 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 12 May 2020 13:08:43 +0100 Subject: [PATCH 4/4] remove whatsnew --- doc/source/whatsnew/v1.1.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 9d55ca3428b68..e56014ed866ca 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -699,7 +699,6 @@ Indexing - Bug in :meth:`PeriodIndex.is_monotonic` incorrectly returning ``True`` when containing leading ``NaT`` entries (:issue:`31437`) - Bug in :meth:`DatetimeIndex.get_loc` raising ``KeyError`` with converted-integer key instead of the user-passed key (:issue:`31425`) - Bug in :meth:`Series.xs` incorrectly returning ``Timestamp`` instead of ``datetime64`` in some object-dtype cases (:issue:`31630`) -- Bug in :meth:`DataFrame.interpolate` raising ``UnboundLocalError`` when specifying the ``axis`` with a string (:issue:`25190`) - Bug in :meth:`DataFrame.iat` incorrectly returning ``Timestamp`` instead of ``datetime`` in some object-dtype cases (:issue:`32809`) - Bug in :meth:`DataFrame.at` when either columns or index is non-unique (:issue:`33041`) - Bug in :meth:`Series.loc` and :meth:`DataFrame.loc` when indexing with an integer key on a object-dtype :class:`Index` that is not all-integers (:issue:`31905`)