Skip to content

Commit 4abe6d8

Browse files
ellequelleBlake Hawkins
authored and
Blake Hawkins
committed
BUG: fix non-existent variable in NDFrame.interpolate (pandas-dev#29142)
1 parent a05829b commit 4abe6d8

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

doc/source/whatsnew/v1.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ Performance improvements
274274
Bug fixes
275275
~~~~~~~~~
276276

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

279278
Categorical
280279
^^^^^^^^^^^
@@ -322,6 +321,7 @@ Numeric
322321
- Bug in :meth:`DataFrame.quantile` with zero-column :class:`DataFrame` incorrectly raising (:issue:`23925`)
323322
- :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`)
324323
- Bug in :class:`DataFrame` logical operations (`&`, `|`, `^`) not matching :class:`Series` behavior by filling NA values (:issue:`28741`)
324+
- Bug in :meth:`DataFrame.interpolate` where specifying axis by name references variable before it is assigned (:issue:`29142`)
325325
-
326326

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

386387
Plotting
387388
^^^^^^^^

pandas/core/generic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -7048,14 +7048,15 @@ def interpolate(
70487048
"""
70497049
inplace = validate_bool_kwarg(inplace, "inplace")
70507050

7051+
axis = self._get_axis_number(axis)
7052+
70517053
if axis == 0:
70527054
ax = self._info_axis_name
70537055
_maybe_transposed_self = self
70547056
elif axis == 1:
70557057
_maybe_transposed_self = self.T
70567058
ax = 1
7057-
else:
7058-
_maybe_transposed_self = self
7059+
70597060
ax = _maybe_transposed_self._get_axis_number(ax)
70607061

70617062
if _maybe_transposed_self.ndim == 2:

pandas/tests/frame/test_missing.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,15 @@ def test_fillna_categorical_nan(self):
391391
cat = Categorical([np.nan, 2, np.nan])
392392
val = Categorical([np.nan, np.nan, np.nan])
393393
df = DataFrame({"cats": cat, "vals": val})
394-
res = df.fillna(df.median())
394+
with tm.assert_produces_warning(RuntimeWarning):
395+
res = df.fillna(df.median())
395396
v_exp = [np.nan, np.nan, np.nan]
396397
df_exp = DataFrame({"cats": [2, 2, 2], "vals": v_exp}, dtype="category")
397398
tm.assert_frame_equal(res, df_exp)
398399

399400
result = df.cats.fillna(np.nan)
400401
tm.assert_series_equal(result, df.cats)
402+
401403
result = df.vals.fillna(np.nan)
402404
tm.assert_series_equal(result, df.vals)
403405

@@ -876,6 +878,23 @@ def test_interp_rowwise(self):
876878
expected = df.interpolate()
877879
assert_frame_equal(result, expected)
878880

881+
@pytest.mark.parametrize(
882+
"axis_name, axis_number",
883+
[
884+
pytest.param("rows", 0, id="rows_0"),
885+
pytest.param("index", 0, id="index_0"),
886+
pytest.param("columns", 1, id="columns_1"),
887+
],
888+
)
889+
def test_interp_axis_names(self, axis_name, axis_number):
890+
# GH 29132: test axis names
891+
data = {0: [0, np.nan, 6], 1: [1, np.nan, 7], 2: [2, 5, 8]}
892+
893+
df = DataFrame(data, dtype=np.float64)
894+
result = df.interpolate(axis=axis_name, method="linear")
895+
expected = df.interpolate(axis=axis_number, method="linear")
896+
assert_frame_equal(result, expected)
897+
879898
def test_rowwise_alt(self):
880899
df = DataFrame(
881900
{

0 commit comments

Comments
 (0)