You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is_nullish() does an inequality test on values to work out if they are NaN:
defis_nullish(value: Any) ->bool:
"""Return true if a value is null, undefined, or NaN."""returnvalueisNoneorvalueisINVALIDorvalue!=value
Unfortunately, numpy arrays break this because they override __eq__ to return a pointwise equality array rather than a boolean.
The comment for is_nullish() suggests that value != value is checking for NaN. If this is the case we could replace it with:
defis_nan(value):
"""Return true if a value is NaN"""try:
returnmath.isnan(value)
exceptTypeError:
returnFalsedefis_nullish(value: Any) ->bool:
"""Return true if a value is null, undefined, or NaN."""returnvalueisNoneorvalueisINVALIDoris_nan(value)
Would this be acceptable? I can provide a PR if it is.
The text was updated successfully, but these errors were encountered:
Right, this value != value is a bit obscure - it has been taken over 1:1 from JavaScript. Not sure why they test it that way, probably because isNaN() was only added to the language in ES 6.
I'm not against changing this and using math.isnan instead. However, I'd rather avoid creating an exception and do something like ... or (isinstance(value, float) and isnan(value)) instead.
We should also add a test that is_nullish(value) is False for some custom object with value != value , that would simulate the numpy array. Feel free to send a PR, otherwise I'll care about this.
I have a custom scalar type for a numpy array:
is_nullish()
does an inequality test on values to work out if they are NaN:Unfortunately, numpy arrays break this because they override
__eq__
to return a pointwise equality array rather than a boolean.The comment for
is_nullish()
suggests thatvalue != value
is checking for NaN. If this is the case we could replace it with:Would this be acceptable? I can provide a PR if it is.
The text was updated successfully, but these errors were encountered: