Skip to content

Fix rolling skew/kurt for low variance windows#63121

Closed
SoulofAkuma wants to merge 5 commits into
pandas-dev:mainfrom
SoulofAkuma:main
Closed

Fix rolling skew/kurt for low variance windows#63121
SoulofAkuma wants to merge 5 commits into
pandas-dev:mainfrom
SoulofAkuma:main

Conversation

@SoulofAkuma
Copy link
Copy Markdown
Contributor

@SoulofAkuma SoulofAkuma commented Nov 15, 2025

Comment thread pandas/tests/window/conftest.py Outdated
Comment thread pandas/tests/window/test_rolling_skew_kurt.py Outdated
Comment thread pandas/_libs/window/aggregations.pyx Outdated
# it could be treated as zero, here we follow the original
# skew/kurt behaviour to check
# m2 <= ((float64_machine_eps * mean) ** 2) * observations
elif m2 <= m2_cutoff:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new implementation for skewness, it shouldn't have much of a problem with numerical instability against degenerate distributions, which is the main reason for this branch. Can you check if it's possible to remove this branch or to just compare against 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed works without this, so removed the branch.

Comment thread pandas/_libs/window/aggregations.pyx Outdated
Copy link
Copy Markdown
Member

@Alvaro-Kothe Alvaro-Kothe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just add an entry in doc/source/whatsnew/v3.0.0.rst

Copy link
Copy Markdown
Member

@Alvaro-Kothe Alvaro-Kothe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a nit in the test.



@pytest.mark.parametrize("sp_func, roll_func", [["kurtosis", "kurt"], ["skew", "skew"]])
def test_low_variance_series(sp_func, roll_func):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add a comment linking to the issue for future contributors.

Suggested change
def test_low_variance_series(sp_func, roll_func):
def test_low_variance_series(sp_func, roll_func):
# GH#62946

@SoulofAkuma
Copy link
Copy Markdown
Contributor Author

Could someone with write permissions to review this? maybe @mroeschke

@github-actions
Copy link
Copy Markdown
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions Bot added the Stale label Dec 20, 2025
@jbrockmendel jbrockmendel added Window rolling, ewma, expanding Reduction Operations sum, mean, min, max, etc. Numeric stability Stability and precision labels Mar 9, 2026
@jbrockmendel
Copy link
Copy Markdown
Member

@Alvaro-Kothe did your reductions PR close this?

@Alvaro-Kothe
Copy link
Copy Markdown
Member

The issue was closed by #64366.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Numeric stability Stability and precision Reduction Operations sum, mean, min, max, etc. Stale Window rolling, ewma, expanding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Rolling.skew and Rolling.kurt return NaN for low-variance windows

3 participants