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
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ Performance improvements
Bug fixes
~~~~~~~~~

- Bug in :meth:`DataFrame.to_html` when using ``formatters=<list>`` and ``max_cols`` together. (:issue:`25955`)

Categorical
^^^^^^^^^^^
Expand Down Expand Up @@ -296,6 +295,7 @@ Numeric
- Bug in :meth:`DataFrame.quantile` with zero-column :class:`DataFrame` incorrectly raising (:issue:`23925`)
- :class:`DataFrame` flex inequality comparisons methods (:meth:`DataFrame.lt`, :meth:`DataFrame.le`, :meth:`DataFrame.gt`, :meth: `DataFrame.ge`) with object-dtype and ``complex`` entries failing to raise ``TypeError`` like their :class:`Series` counterparts (:issue:`28079`)
- Bug in :class:`DataFrame` logical operations (`&`, `|`, `^`) not matching :class:`Series` behavior by filling NA values (:issue:`28741`)
- Bug in :meth:`DataFrame.interpolate` where specifying axis by name references variable before it is assigned (:issue:`29142`)
-

Conversion
Expand Down Expand Up @@ -356,6 +356,7 @@ I/O
- Bug in :meth:`DataFrame.read_json` where using ``orient="index"`` would not maintain the order (:issue:`28557`)
- Bug in :meth:`DataFrame.to_html` where the length of the ``formatters`` argument was not verified (:issue:`28469`)
- Bug in :meth:`pandas.io.formats.style.Styler` formatting for floating values not displaying decimals correctly (:issue:`13257`)
- Bug in :meth:`DataFrame.to_html` when using ``formatters=<list>`` and ``max_cols`` together. (:issue:`25955`)

Plotting
^^^^^^^^
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
21 changes: 20 additions & 1 deletion pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,15 @@ def test_fillna_categorical_nan(self):
cat = Categorical([np.nan, 2, np.nan])
val = Categorical([np.nan, np.nan, np.nan])
df = DataFrame({"cats": cat, "vals": val})
res = df.fillna(df.median())
with tm.assert_produces_warning(RuntimeWarning):
res = df.fillna(df.median())
v_exp = [np.nan, np.nan, np.nan]
df_exp = DataFrame({"cats": [2, 2, 2], "vals": v_exp}, dtype="category")
tm.assert_frame_equal(res, df_exp)

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 @@ -876,6 +878,23 @@ def test_interp_rowwise(self):
expected = df.interpolate()
assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"axis_name, axis_number",
[
pytest.param("rows", 0, id="rows_0"),
pytest.param("index", 0, id="index_0"),
pytest.param("columns", 1, id="columns_1"),
],
)
def test_interp_axis_names(self, axis_name, axis_number):
# GH 29132: test axis names
data = {0: [0, np.nan, 6], 1: [1, np.nan, 7], 2: [2, 5, 8]}

df = DataFrame(data, dtype=np.float64)
result = df.interpolate(axis=axis_name, method="linear")
expected = df.interpolate(axis=axis_number, method="linear")
assert_frame_equal(result, expected)

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