Skip to content

BUG: fix non-existent variable in NDFrame.interpolate #29142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 25, 2019
Merged
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Bug fixes
~~~~~~~~~

- Bug in :meth:`DataFrame.to_html` when using ``formatters=<list>`` and ``max_cols`` together. (:issue:`25955`)
- Bug in :meth:`DataFrame.interpolate` where specifying axis by name references variable before it is assigned (:issue:`29132`)

Categorical
^^^^^^^^^^^
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7023,14 +7023,15 @@ def interpolate(
"""
inplace = validate_bool_kwarg(inplace, "inplace")

axis = self._get_axis_number(axis)

if axis == 0:
ax = self._info_axis_name
_maybe_transposed_self = self
elif axis == 1:
_maybe_transposed_self = self.T
ax = 1
else:
_maybe_transposed_self = self

ax = _maybe_transposed_self._get_axis_number(ax)

if _maybe_transposed_self.ndim == 2:
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def test_fillna_categorical_nan(self):

result = df.cats.fillna(np.nan)
tm.assert_series_equal(result, df.cats)

result = df.vals.fillna(np.nan)
tm.assert_series_equal(result, df.vals)

Expand Down Expand Up @@ -872,10 +873,22 @@ def test_interp_rowwise(self):
result = df.interpolate(axis=1, method="values")
assert_frame_equal(result, expected)

# GH 29142: test axis names
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than adding tests like this, can you create a new test function and paramterize on the axis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a new parametrized function in the latest commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest is returning with an uncaught warning in the same file from a call to df.median(). Should I add tm.assert_produces_warning()?

pandas/tests/frame/test_missing.py::TestDataFrameMissingData::test_fillna_categorical_nan
python3.7/site-packages/numpy/lib/nanfunctions.py:1115: RuntimeWarning: All-NaN slice encountered
    overwrite_input=overwrite_input)

result = df.interpolate(axis="columns", method="values")
assert_frame_equal(result, expected)

result = df.interpolate(axis=0)
expected = df.interpolate()
assert_frame_equal(result, expected)

# GH 29142: test axis names
result = df.interpolate(axis="rows", method="values")
assert_frame_equal(result, expected)

# GH 29142: test axis names
result = df.interpolate(axis="index", method="values")
assert_frame_equal(result, expected)

def test_rowwise_alt(self):
df = DataFrame(
{
Expand Down