-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
Calculations: Update First * and Last * reducers to exclude NaNs #77323
Conversation
@@ -418,7 +418,7 @@ function calculateFirstNotNull(field: Field, ignoreNulls: boolean, nullAsZero: b | |||
const data = field.values; | |||
for (let idx = 0; idx < data.length; idx++) { | |||
const v = data[idx]; | |||
if (v != null && v !== undefined) { | |||
if (v != null && v !== undefined && !isNaN(v)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably if (v != null && !Number.isNaN(v))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch - Number.isNaN
doesn't infer that value is number
and instead is unknown
Currently working on adding a test and the reduceFields
function isn't playing nicely and still is returning NaN
instead of the expected valid value in the test suite 🙃
}, | ||
]; | ||
|
||
const stats = reduceField({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats returns:
{
sum: 200,
max: 200,
min: 200,
logmin: 200,
mean: 200,
last: NaN,
first: NaN,
lastNotNull: 200,
firstNotNull: 200,
count: 3,
nonNullCount: 1,
allIsNull: false,
allIsZero: false,
range: 0,
diff: 0,
delta: 0,
step: null,
diffperc: 0,
previousDeltaUp: true
}
@@ -320,8 +320,8 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: | |||
|
|||
calcs.count++; | |||
|
|||
if (currentValue != null) { | |||
// null || undefined | |||
if (currentValue != null && !Number.isNaN(currentValue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little scared of modifying the doStandardCalcs
function but this seems reasonable 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryantxu this is a change I'm a little worried about in this PR (modifying doStandardCalcs
function) - does this seem reasonable?
}, | ||
{ | ||
data: [NaN, NaN, NaN], // All NaN | ||
result: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we want special handling in this case (i.e. if all NaN return NaN vs null)
if (v != null && v !== undefined && !isNaN(v)) { | ||
return { firstNotNull: v }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the undefined part required? I think != null covers both null and undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foo != null
will check if foo
is either null
or undefined
so we should be good with this simplification 👍
we could go one step further and also omit Infinity and -Infinity by switching to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite |
I think that may be one step too far, but I do not feel too strongly |
…-update-NaN-handling
I don't feel super strongly on this either way - though I am not informed on use cases where seeing +/- inf makes sense. Maybe for now we could move forward with just avoiding NaN and see what user sentiment / feedback is for that initial change? What do you think @leeoniya? |
What is this feature?
Exclude NaN values as part of
Last *
andFirst *
reducers.NaN.handling.mov
NaN_-1698445566753.json.txt
Why do we need this feature?
NaN
is not typically considered a "valid" value and so excluding it makes sense through these reducers as they are designed to return either the first or last "valid" value.Who is this feature for?
Users that want to receive the first or last "valid" value in their data.
Which issue(s) does this PR fix?:
Fixes #59862
Special notes for your reviewer:
Please check that: