Repository navigation
[Python] Fix DataFrame var, std, skew and kurtosis with skipna=False - #41874
anishmehta24 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR fixes DeferredSeries.var (and transitively DeferredSeries.std, DeferredDataFrame.var, and DeferredDataFrame.std) to properly respect skipna=False by checking self.hasnans and returning NaN when any NaN values are present. The implementation is clean, consistent with existing moment aggregations (skew and kurtosis) in frames.py, and well-covered by unit tests.
🔍 General Feedback
- Reusing the
self.hasnans+result.apply(..., other=[has_na], name='handle_na')pattern fromskewandkurtosiskeeps the moment aggregation implementations uniform acrossDeferredSeries. - The unit tests in
frames_test.pythoroughly cover bothSeriesandDataFrame(including mixed columns with and withoutNaNs) forvarandstd.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @jrmccluskey for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
jrmccluskey
left a comment
There was a problem hiding this comment.
LGTM, thanks! Please rebase onto current master so we can get clean CI run before merging
Fixes #41873
var,skewandkurtosiscompute partition moments with pandasstd,sumandmean, which skip NaN, while the row count includes it. Withskipna=Truethe NaN rows are dropped first, but withskipna=Falsea NaN that shares a partition with other values is ignored, so the result is a number where pandas gives NaN. Withskipna=Falsethese methods now return NaN when the Series has any NaN, and otherwise the same result as before.stdandkurtgo throughvarandkurtosis, andDataFrame.var/std(skipna=False)through the Series methods, so they are fixed too.Added
test_moments_with_na_and_skipna_falseto frames_test.py (40 rows, so every NaN shares a test partition with other values). It fails on master. The apache_beam/dataframe tests and the Series, DataFrame, NDFrame and GroupBy pandas doctests pass.