fix: return 0 for constant input in incr/skewness and incr/kurtosis#13197
fix: return 0 for constant input in incr/skewness and incr/kurtosis#13197apoorva-01 wants to merge 1 commit into
incr/skewness and incr/kurtosis#13197Conversation
The incremental skewness and kurtosis accumulators compute a population moment by dividing by a power of the second central moment, `M2`. When every provided value is equal, `M2` is exactly zero, so the division is `0/0` and the accumulators return `NaN` rather than the expected `0`. Guard against a zero `M2` in both accumulators, in the running update and the no-argument query paths, and return `0`, consistent with the skewness and excess kurtosis of a constant data set. This also resolves the same behavior in `incr/nanskewness`, which wraps `incr/skewness`. Signed-off-by: Apoorva Verma <vermaapoorva0510@gmail.com>
|
Hello! Thank you for your contribution to stdlib. We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
This acknowledgment confirms that you've read the guidelines, which include:
We can't review or accept contributions without this acknowledgment. Thank you for your understanding and cooperation. We look forward to reviewing your contribution! |
|
👋 Hi there! 👋 And thank you for opening your first pull request! We will review it shortly. 🏃 💨 Getting Started
Next Steps
Running Tests LocallyYou can use # Run tests for all packages in the math namespace:
make test TESTS_FILTER=".*/@stdlib/math/.*"
# Run benchmarks for a specific package:
make benchmark BENCHMARKS_FILTER=".*/@stdlib/math/base/special/sin/.*"If you haven't heard back from us within two weeks, please ping us by tagging the "reviewers" team in a comment on this PR. If you have any further questions while waiting for a response, please join our Zulip community to chat with project maintainers and other community members. We appreciate your contribution! Documentation Links |
Resolves #287.
Description
@stdlib/stats/incr/skewnessand@stdlib/stats/incr/kurtosisreturningNaNinstead of0when every provided value is equal.The accumulators divide by a power of the second central moment
M2when computing the population moment. For constant input,M2is exactly0, so the computation is a0/0division (sqrt(N)*M3 / pow(M2, 1.5)for skewness;N*M4 / (M2*M2)for kurtosis), yieldingNaN. The expected value for a constant data set is0(same as the issue's pandas reference, pandas-dev/pandas#18044). The fix guards against a zeroM2in both accumulators, in both the running-update and no-argument query paths.Scope: these two are the only
stats/incrpackages performing thisM2division (noincr/m*variants, noincr/nankurtosis).incr/nanskewnesswrapsincr/skewnessand inherits the fix;incr/summaryconsumes both and its suite still passes.Related Issues
Questions
0.0for the all-equal case in both skewness and excess kurtosis. Skewness0matches the issue; excess kurtosis0is the analogous convention for a constant series — happy to adjust if you'd prefer a different sentinel for kurtosis.Other
Tested: reproduced the MWE (100 ×
10.0) →NaNbefore /0after for skewness, kurtosis, and nanskewness. Added a regression test to each package (asserting both return paths give0), proven to fail when themain.jsguard is reverted. Suites: skewness 34/34, kurtosis 36/36, nanskewness 16/16, summary 6/6.Checklist