Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _create_data(self, obj: NDFrameT, numeric_only: bool = False) -> NDFrameT:
"""
# filter out the on from the object
if self.on is not None and not isinstance(self.on, Index) and obj.ndim == 2:
obj = obj.reindex(columns=obj.columns.difference([self.on]))
obj = obj.reindex(columns=obj.columns.difference([self.on], sort=False))
if obj.ndim > 1 and numeric_only:
obj = self._make_numeric_only(obj)
return obj
Expand Down
32 changes: 32 additions & 0 deletions pandas/tests/window/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,38 @@ def f(x):
)
tm.assert_frame_equal(result, expected)

def test_table_method_rolling_apply_col_order(self):
# GH#59666
def f(x):
return np.nanmean(x[:, 0] - x[:, 1])

df = DataFrame(
{
"a": [1, 2, 3, 4, 5, 6],
"b": [6, 7, 8, 5, 6, 7],
}
)
result = df.rolling(3, method="table", min_periods=0)[["a", "b"]].apply(
f, raw=True, engine="numba"
)
expected = DataFrame(
{
"a": [-5, -5, -5, -3.66667, -2.33333, -1],
"b": [-5, -5, -5, -3.66667, -2.33333, -1],
}
)
tm.assert_almost_equal(result, expected)
result = df.rolling(3, method="table", min_periods=0)[["b", "a"]].apply(
f, raw=True, engine="numba"
)
expected = DataFrame(
{
"b": [5, 5, 5, 3.66667, 2.33333, 1],
"a": [5, 5, 5, 3.66667, 2.33333, 1],
}
)
tm.assert_almost_equal(result, expected)

def test_table_method_rolling_weighted_mean(self, step):
def weighted_mean(x):
arr = np.ones((1, x.shape[1]))
Expand Down
Loading