Repository navigation
feat: Handle edge case with corr with single row and NaN - #18677
Conversation
| // If BOTH sum_x AND sum_y are NaN, then both input values are NaN → return NaN | ||
| // If only ONE of them is NaN, then only one input value is NaN → return NULL | ||
| // This takes precedence over the count < 2 check | ||
| if sum_x.is_nan() && sum_y.is_nan() { |
There was a problem hiding this comment.
this is the actual change
martin-g
left a comment
There was a problem hiding this comment.
Does CorrelationAccumulator::evaluate() also need improvements related to NaN ?
At the moment if count < 2 it returns return Ok(ScalarValue::Float64(None)); without any checks for NAN.
https://github.com/comphead/arrow-datafusion/blob/2d344a58b48af6c866b6ff024dbd00aa0c8d8293/datafusion/functions-aggregate/src/correlation.rs#L201
| // Check for NaN in the sums BEFORE checking count | ||
| // If BOTH sum_x AND sum_y are NaN, then both input values are NaN → return NaN | ||
| // If only ONE of them is NaN, then only one input value is NaN → return NULL | ||
| // This takes precedence over the count < 2 check |
There was a problem hiding this comment.
IMO line 434 should be moved one line up.
At the moment it is not very clear what takes precedence. I think you want to say that the checks for NaN should be before the check for count < 2 but it also sounds like the check for one of them being NaN should be before count < 2, but they are done together.
There was a problem hiding this comment.
I was thinking about the same on CorrelationAccumulator::evaluate() but the test passed without having CorrelationAccumulator amended, one thing comes to my mind is it might depend on batch_size, checking this
There was a problem hiding this comment.
I found another edge case and added tests for that as well
|
@andygrove @mbutrovich please take a look |
…18677) ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#18659. ## Rationale for this change Fix an edge case in `corr` and `NaN` <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
…18677) ## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#18659. ## Rationale for this change Fix an edge case in `corr` and `NaN` <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
Which issue does this PR close?
corrincorrect result withNaN#18659.Rationale for this change
Fix an edge case in
corrandNaNWhat changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?