-
Notifications
You must be signed in to change notification settings - Fork 61
MNT Support numpy2 #429
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
Merged
Merged
MNT Support numpy2 #429
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
75e5ffa
Revert "MNT space creator only after merge"
adrinjalali b73d1fd
MNT fix card tests
adrinjalali a7418f0
fix np.random.Generator equality check
adrinjalali 326dc6f
save numpy bit_generator's seed sequence
adrinjalali 1e5d3bb
ignore np.core deprecation warning in whichmodule
adrinjalali 1aeb2ad
TST check something else since np.ma.core.MaskedArray is now np.ma.Ma…
adrinjalali 6318c68
safer guard against quantile_forest import fails
adrinjalali 402266a
test and fix numpy_v1
adrinjalali 9045ecd
test numpy 1 as well
adrinjalali 70349ba
add missing file
adrinjalali b26440c
fix workflow
adrinjalali b7cb43b
absolute imports
adrinjalali 86b2fe3
ignore mypy already defined error
adrinjalali 4d233e3
another go at testing numpy1
adrinjalali d2e85d7
upgrade pip
adrinjalali 3620f34
ignore mypy
adrinjalali b501b50
make windows happy
adrinjalali ca586dc
remove unused code
adrinjalali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,4 @@ | |
| version Y instead. | ||
|
|
||
| """ | ||
| PROTOCOL = 1 | ||
| PROTOCOL = 2 | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Optional, Sequence | ||
|
|
||
| import numpy as np | ||
|
|
||
| from skops.io._audit import Node, get_tree | ||
| from skops.io._utils import LoadContext, gettype | ||
|
|
||
| PROTOCOL = 1 | ||
|
|
||
|
|
||
| class RandomGeneratorNode(Node): | ||
| def __init__( | ||
| self, | ||
| state: dict[str, Any], | ||
| load_context: LoadContext, | ||
| trusted: Optional[Sequence[str]] = None, | ||
| ) -> None: | ||
| super().__init__(state, load_context, trusted) | ||
| self.children = { | ||
| "bit_generator_state": get_tree( | ||
| state["content"]["bit_generator"], load_context, trusted=trusted | ||
| ) | ||
| } | ||
| self.trusted = self._get_trusted(trusted, [np.random.Generator]) | ||
|
|
||
| def _construct(self): | ||
| # first restore the state of the bit generator | ||
| bit_generator_state = self.children["bit_generator_state"].construct() | ||
| bit_generator_cls = gettype( | ||
| "numpy.random", bit_generator_state["bit_generator"] | ||
| ) | ||
| bit_generator = bit_generator_cls() | ||
| bit_generator.state = bit_generator_state | ||
|
|
||
| # next create the generator instance | ||
| return gettype(self.module_name, self.class_name)(bit_generator=bit_generator) | ||
|
|
||
|
|
||
| # tuples of type and function that creates the instance of that type | ||
| NODE_TYPE_MAPPING = { | ||
| ("RandomGeneratorNode", PROTOCOL): RandomGeneratorNode, | ||
| } |
Oops, something went wrong.
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.
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.
Honestly, I can't quite remember how it worked: Would adding an item here affect compatibility? I guess it's backwards compatible as witnessed by the test but not forwards compatible? Also, is this a change for numpy v2 or was it an oversight of not having this?
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.
So in
numpy~=1we have:while
numpy=2does this:and that means our check fails, and while fixing the check going recursively in what's in the output of
__reduce__, I noticed we're not saving the seed sequence's state. It doesn't seem to have an affect in the next few generated numbers as I checked, but it's something which can be stored and loaded, so I added it.