fix: use utility isNaN for consistent max and min results#3389
Conversation
|
Thanks very much for the PR! Generally, it looks solid. Just two items from review:
Such injections of Personally, I see three possible ways the conflict could be eliminated: (A) have the internal factory be called something like If @josdejong does want to steer away from using injected |
Thanks for the review! I will add more tests and update the documentation appropriately. Regarding your second point, I agree it can be confusing, and I will leave it to Jos to decide how he wants to proceed. For now, I will use option C as a placeholder in this particular implementation, as I don't see it causing any side effects. |
|
Excellent, thank you! Just awaiting @josdejong's decision on how mathjs should handle isNaN shadowing internally before final review. |
So @orelbn employed my suggestion of avoiding the shadowing of built-in isNaN by mapping the injected isNaN to mathIsNaN in the factory implementation. If you think this is the solution of choice for the potential shadowing problem, then perhaps this PR should make the analogous renaming in the other three statistics functions that inject isNaN. I made two other suggestions above about dealing with this shadowing concern; if you like either of them better then perhaps this PR should embark on one of them? Otherwise yes this PR seems ready to go. |
|
I think the solution of using I'll merge the PR as it is now, and solve the other occurrences of shadowing |
|
Published now in |
Addresses: #3387
Description:
largerandsmallerfunctions will return false when comparing any value that isNaN, so that the result will not be changedAdditional Notes:
I don't think this is necessarily a big issue because you would have to be comparing a Unit/BigNumber that has a value that is NaN. I think having undefined behaviour for that might be okay or throwing an error (so let me know if you decide not to address the issue).
AI Summary:
This pull request includes changes to the
maxandminfunctions to improve their handling ofNaNvalues and adds corresponding unit tests. The key changes involve updating dependencies, modifying the logic for handlingNaNvalues, and enhancing test coverage.Enhancements to
maxandminfunctions:src/expression/transform/max.transform.js: AddedisNaNto the dependencies ofcreateMaxTransform.src/expression/transform/min.transform.js: AddedisNaNto the dependencies ofcreateMinTransform.src/function/statistics/max.js: AddedisNaNto the dependencies ofcreateMaxand modified the logic to handleNaNvalues correctly. [1] [2]src/function/statistics/min.js: AddedisNaNto the dependencies ofcreateMinand modified the logic to handleNaNvalues correctly. [1] [2]Unit tests:
test/unit-tests/function/statistics/max.test.js: Added tests to verify the handling ofNaNvalues in themaxfunction. [1] [2] [3]test/unit-tests/function/statistics/min.test.js: Added tests to verify the handling ofNaNvalues in theminfunction. [1] [2] [3]