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 :func:`pandas.core.generic.NDFrame.interpolate` where specifying axis by name references variable before it is assigned (:issue:`29132`)
Copy link
Contributor

Choose a reason for hiding this comment

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

These are user facing, so we shouldn't reference NDFrame. Instead, refer to just :meth:`DataFrame.interpolate`, even if it affects Series as well.

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 see!


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
5 changes: 5 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,8 @@ def test_deprecated_get_dtype_counts(self):
df = DataFrame([1])
with tm.assert_produces_warning(FutureWarning):
df.get_dtype_counts()

@pytest.mark.parametrize("axis", [0, 1, "index", "columns", "rows"])
def test_interpolate_axis_argument(self, axis):
Copy link
Member

Choose a reason for hiding this comment

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

Reference issue number above this line as a comment.

# GH 29142
assert DataFrame([0]).interpolate(axis=axis)