Skip to content

BUG: Fix rolling().mean() returning NaNs on reassignment (#61841) #61845

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

Closed

Conversation

abujabarmubarak
Copy link

Problem

Fixes issue #61841 — calling .rolling().mean() twice on a copied DataFrame was returning all NaNs on the second run.

This happened due to a slicing operation ([::self.step]) in _apply_columnwise, which broke result alignment when overwriting the same column.

Solution

Removed the [:: self.step] slicing from the return statement. This restores full alignment and fixes the regression.

Test Case

Tested locally with this code:

df = pd.DataFrame({"Close": list(range(1, 31))})
df = df.copy()
df["SMA20"] = df["Close"].rolling(20).mean()
df["SMA20"] = df["Close"].rolling(20).mean()
print(df.tail())
<img width="1269" height="377" alt="Screenshot 2025-07-13 201135" src="https://github.com/user-attachments/assets/c1cbe325-28c6-4a39-bf98-861492d9295c" />

Pandas Development Team and others added 30 commits December 22, 2023 11:18
…re) (#56612)

Backport PR #56595: TST/CLN: Inline seldom used fixture

Co-authored-by: Matthew Roeschke <[email protected]>
…6620)

Backport PR #56615: CI: Fix deprecation warnings

Co-authored-by: Patrick Hoefler <[email protected]>
…#56624)

Backport PR #56617: TYP: some return types from ruff

Co-authored-by: Torsten Wörtwein <[email protected]>
Backport PR #56636: DOC: Fixup CoW userguide

Co-authored-by: Patrick Hoefler <[email protected]>
…new) (#56640)

Backport PR #56632: DOC: Minor fixups for 2.2.0 whatsnew

Co-authored-by: Richard Shadrach <[email protected]>
…arrow floats to numpy floats) (#56648)

Backport PR #56644: BUG: Series.to_numpy raising for arrow floats to numpy floats

Co-authored-by: Patrick Hoefler <[email protected]>
…rrow duration types) (#56656)

Backport PR #56650: ENH: Implement dt methods for pyarrow duration types

Co-authored-by: Matthew Roeschke <[email protected]>
…56655)

Backport PR #56647: floordiv fix for large values

Co-authored-by: rohanjain101 <[email protected]>
…atetime columns with timedelta columns) (#56658)

Backport PR #56613: BUG: Added raising when merging datetime columns with timedelta columns

Co-authored-by: Huanghz2001 <[email protected]>
…x raising read-only error) (#56660)

Backport PR #56635: CoW: Boolean indexer in MultiIndex raising read-only error

Co-authored-by: Patrick Hoefler <[email protected]>
…ble in 2.2 whatsnew) (#56662)

Backport PR #56641: DOC: Add optional dependencies table in 2.2 whatsnew

Co-authored-by: Matthew Roeschke <[email protected]>
…type) (#56665)

Backport PR #56370: BUG: rolling with datetime ArrowDtype

Co-authored-by: Matthew Roeschke <[email protected]>
…erly respecting check-dtype) (#56668)

Backport PR #56654: BUG: assert_series_equal not properly respecting check-dtype

Co-authored-by: Patrick Hoefler <[email protected]>
…6669)

Backport PR #56664: CI: Run jobs on 2.2.x branch

Co-authored-by: Matthew Roeschke <[email protected]>
…heck for future annotation import) (#56683)

Backport PR #56666: STY: Use ruff instead of pygrep check for future annotation import

Co-authored-by: Matthew Roeschke <[email protected]>
Backport PR #56682: CLN: NEP 50 followups

Co-authored-by: Thomas Li <[email protected]>
…ession) (#56686)

Backport PR #56312: DOC: Add whatsnew for concat regression

Co-authored-by: Thomas Li <[email protected]>
…ries.struct.field) (#56698)

Backport PR #56167: [ENH]: Expand types allowed in Series.struct.field

Co-authored-by: Tom Augspurger <[email protected]>
….fullmatch matches partial string. issue #56652) (#56715)

Backport PR #56691: Bug pyarrow implementation of str.fullmatch matches partial string. issue #56652

Co-authored-by: JackCollins91 <[email protected]>
… coerce) (#56719)

Backport PR #56699: DOC: Corrected typo in warning on coerce

Co-authored-by: aaron-robeson-8451 <[email protected]>
…fill) (#56720)

Backport PR #56616: BUG: Add limit_area to EA ffill/bfill

Co-authored-by: Richard Shadrach <[email protected]>
…56725)

Backport PR #56721: DOC: Fixup read_csv docstring

Co-authored-by: Patrick Hoefler <[email protected]>
…orical using dictionary as categories) (#56723)

Backport PR #56672: BUG: dictionary type astype categorical using dictionary as categories

Co-authored-by: Patrick Hoefler <[email protected]>
…cel) (#56730)

Backport PR #56543: DOC: Update docstring for read_excel

Co-authored-by: Patrick Hoefler <[email protected]>
… for pyarrow types with large divisor and avoid floating points for floordiv) (#56744)

Backport PR #56677: Fix integral truediv and floordiv for pyarrow types with large divisor and avoid floating points for floordiv

Co-authored-by: rohanjain101 <[email protected]>
…vation in groupby column selection) (#56770)

Backport PR #56761: BUG: fix subclass metadata preservation in groupby column selection

Co-authored-by: Joris Van den Bossche <[email protected]>
… bools for ea dtypes) (#56780)

Backport PR #56769: BUG: replace matching Floats with bools for ea dtypes

Co-authored-by: Patrick Hoefler <[email protected]>
…lable bool dtype) (#56782)

Backport PR #56767: BUG: Series.round raising for nullable bool dtype

Co-authored-by: Patrick Hoefler <[email protected]>
…pes correctly) (#56783)

Backport PR #56771: BUG: to_stata not handling ea dtypes correctly

Co-authored-by: Patrick Hoefler <[email protected]>
meeseeksmachine and others added 28 commits March 12, 2024 14:15
Backport PR #57821: Fix doc build

Co-authored-by: Trinh Quoc Anh <[email protected]>
….rst) (#57832)

Backport PR #57830: DOC: Pin dask/dask-expr for scale.rst

Co-authored-by: Matthew Roeschke <[email protected]>
…ion) (#57834)

Backport PR #57796: Fix issue with Tempita recompilation

Co-authored-by: William Ayd <[email protected]>
…normalize from docs) (#57854)

Backport PR #57848: DOC: Remove duplicated Series.dt.normalize from docs

Co-authored-by: Marc Garcia <[email protected]>
…in favor of linking to ecosystem docs. (#57861)

Co-authored-by: Yuki Kitayama <[email protected]>
…5 to 2.17.0) (#57888)

Backport PR #57883: Bump pypa/cibuildwheel from 2.16.5 to 2.17.0

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…57898)

Backport PR #57892: CI: xfail Pyarrow slicing test

Co-authored-by: Matthew Roeschke <[email protected]>
…ith Dask, dict-like, Series) (#57899)

Backport PR #57889: BUG: Handle Series construction with Dask, dict-like, Series

Co-authored-by: Matthew Roeschke <[email protected]>
…compilation (#57796)") (#57907)

Backport PR #57905: Revert "Fix issue with Tempita recompilation (#57796)"

Co-authored-by: William Ayd <[email protected]>
Backport PR #57886: CI: Remove ASAN job

Co-authored-by: William Ayd <[email protected]>
…hod) (#57940)

Backport PR #57029: DOC: Add `DataFrame.to_numpy` method

Co-authored-by: Zhengbo Wang <[email protected]>
…for to_datetime(str, unit=...)) (#58034)

Backport PR #57548: Fix accidental loss-of-precision for to_datetime(str, unit=...)

Co-authored-by: Elliott Sales de Andrade <[email protected]>
…ol errors on Boolean columns) (#58036)

Backport PR #57758: BUG: DataFrame Interchange Protocol errors on Boolean columns

Co-authored-by: Marco Edward Gorelli <[email protected]>
…f table when using public schema) (#58050)

Backport PR #57974: BUG: Fixed ADBC to_sql creation of table when using public schema

Co-authored-by: Shabab Karim <[email protected]>
…class init) (#58008)

* Backport PR #57553: API: avoid passing Manager to subclass __init__

* whatsnew, type ignores

* merge 2.2.2 file from main

* rebase on 2.2.x whatsnew
…58080)

Backport PR #58075: DOC: whatsnew note for #57553

Co-authored-by: jbrockmendel <[email protected]>
Revert "BLD: Pin numpy on 2.2.x (#56812)"

This reverts commit 24ea67f.
…ifulsoup4 4.13.0b2) (#58137)

Backport PR #58100: MNT: fix compatibility with beautifulsoup4 4.13.0b2

Co-authored-by: Clément Robert <[email protected]>
…58140)

Backport PR #58138: BLD: Fix nightlies not building

Co-authored-by: Thomas Li <[email protected]>
…w_index) (#58187)

Backport PR #58181: CI: correct error msg in `test_view_index`
…rc1) (#58105)

Backport PR #58087: BLD: Build wheels using numpy 2.0rc1

Co-authored-by: Thomas Li <[email protected]>
…s for 2.2.2) (#58206)

Backport PR #58203: DOC: Add release date/contributors for 2.2.2

Co-authored-by: Thomas Li <[email protected]>
#58208)

Backport PR #58202: DOC/TST: Document numpy 2.0 support and add tests for string array
@mroeschke
Copy link
Member

Thanks for the PR, but please contain the changes to one open pull request at a time

@mroeschke mroeschke closed this Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.