Skip to content
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

update numpy and fix numpy records #117

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- bump: minor
changes:
fixed:
- Bump numpy version
- Fix numpy record compatibility issue
4 changes: 3 additions & 1 deletion policyengine_core/parameters/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


def contains_nan(vector):
if numpy.issubdtype(vector.dtype, numpy.record):
if numpy.issubdtype(vector.dtype, numpy.record) or numpy.issubdtype(
vector.dtype, numpy.void
):
return any([contains_nan(vector[name]) for name in vector.dtype.names])
else:
return numpy.isnan(vector).any()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def build_from_node(
node: "ParameterNode",
) -> "VectorialParameterNodeAtInstant":
VectorialParameterNodeAtInstant.check_node_vectorisable(node)
subnodes_name = node._children.keys()
subnodes_name = sorted(node._children.keys())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry just remind me why this is necessary? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this change from this commit: openfisca/openfisca-core@c0782fa
Without it I get the TypeError on unit test runs.

# Recursively vectorize the children of the node
vectorial_subnodes = tuple(
[
Expand Down Expand Up @@ -227,7 +227,9 @@ def __getitem__(self, key: str) -> Any:
)

# If the result is not a leaf, wrap the result in a vectorial node.
if numpy.issubdtype(result.dtype, numpy.record):
if numpy.issubdtype(
result.dtype, numpy.record
) or numpy.issubdtype(result.dtype, numpy.void):
return VectorialParameterNodeAtInstant(
self._name, result.view(numpy.recarray), self._instant_str
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

general_requirements = [
"pytest>=7,<8",
"numpy>=1.21,<1.22",
"numpy >=1.24.2, <1.25",
"black",
"linecheck<1",
"yaml-changelog<1",
Expand Down