Skip to content

Commit 4bd069f

Browse files
authored
BUG: rolling(axis=1).apply() raising ValueError (#45925)
1 parent 0a7507d commit 4bd069f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v1.4.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Bug fixes
3636
- Stopped emitting unnecessary ``FutureWarning`` in :meth:`DataFrame.sort_values` with sparse columns (:issue:`45618`)
3737
- Fixed window aggregations in :meth:`DataFrame.rolling` and :meth:`Series.rolling` to skip over unused elements (:issue:`45647`)
3838
- Fixed builtin highlighters in :class:`.Styler` to be responsive to ``NA`` with nullable dtypes (:issue:`45804`)
39+
- Bug in :meth:`~Rolling.apply` with ``axis=1`` raising an erroneous ``ValueError`` (:issue:`45912`)
3940

4041
.. ---------------------------------------------------------------------------
4142

pandas/core/window/rolling.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,8 @@ def _generate_cython_apply_func(
13431343

13441344
def apply_func(values, begin, end, min_periods, raw=raw):
13451345
if not raw:
1346-
values = Series(values, index=self.obj.index)
1346+
# GH 45912
1347+
values = Series(values, index=self._on)
13471348
return window_func(values, begin, end, min_periods)
13481349

13491350
return apply_func

pandas/tests/window/test_apply.py

+8
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,11 @@ def test_center_reindex_frame(raw, frame):
308308
)
309309
frame_rs = frame.rolling(window=25, min_periods=minp, center=True).apply(f, raw=raw)
310310
tm.assert_frame_equal(frame_xp, frame_rs)
311+
312+
313+
def test_axis1(raw):
314+
# GH 45912
315+
df = DataFrame([1, 2])
316+
result = df.rolling(window=1, axis=1).apply(np.sum, raw=raw)
317+
expected = DataFrame([1.0, 2.0])
318+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)