Repository navigation
Conversation
np.float_ was removed in NumPy 2.0, so the float check raised AttributeError for any value past the int branch. The date branch used an undefined name (obj). Add tests for the encoder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MLJSONEncoderhad two bugs insupervised/utils/jsonencoder.py:np.float_, which NumPy 2.0 removed. The package requiresnumpy>=2.0.0, so any value that got past the int branch (a numpy float, an ndarray, a date) raisedAttributeErrorinstead of being encoded.obj, which is not defined indefault(self, o), so adate/datetimewould have raisedNameError.This removes
np.float_(np.float64already covers it) and usesoin the date branch. It also addstests/tests_utils/test_jsonencoder.py(numpy ints and floats, an ndarray,dateanddatetime, and an unknown type that must still raiseTypeError).How I tested it
In a
python:3.12-slimcontainer with NumPy 2, I ran the new test file against the encoder module on its own (the rest of the package's heavy dependencies were not installed):master: 4 failed, all withAttributeError: `np.float_` was removed in the NumPy 2.0 release.I did not run the full test suite.
I used Claude (an AI assistant) to help with this change; I reviewed it and ran the checks above.