Conversation
For dim=1 the function returned np.arange(0, order + 1, dtype=np.int). np.int was removed in NumPy 1.24, so Grid.moments(..., type_mom="cartesian") on a grid with points of shape (N, 1) raised AttributeError. The result was also the wrong shape: every order from 0 to n instead of the single row [n] that the 2D and 3D branches return, so the np.vstack in Grid.moments could not have stacked the rows anyway. Return [[order]] for dim=1, matching the other dimensions.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix is consistent with higher-dimensional behavior and is adequately covered by direct and integration tests.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes 1D Cartesian order generation so Grid.moments works correctly with modern NumPy.
Changes:
- Returns a single
[[order]]row for 1D Cartesian orders. - Adds direct order-generation and end-to-end moment tests.
| File | Description |
|---|---|
src/grid/utils.py |
Corrects 1D Cartesian order output. |
src/grid/tests/test_utils.py |
Tests generated 1D order shape and values. |
src/grid/tests/test_grid.py |
Tests 1D Cartesian moment calculations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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.
Fixes #334.
generate_orders_horton_order(order, "cartesian", dim=1)returnednp.arange(0, order + 1, dtype=np.int):np.intwas removed in NumPy 1.24, soGrid.moments(..., type_mom="cartesian")on a grid with points of shape(N, 1)raisedAttributeError.[n]that the 2D and 3D branches return, so thenp.vstackinGrid.momentscouldn't stack the rows even with a valid dtype.The fix returns
[[order]]fordim=1, like the other dimensions.Tests
test_generate_orders_horton_order_cartesian_one_dimensioncovers the function directly.TestGrid1D.test_cartesian_momentschecks the moments up to order 3 against sums computed by hand.Both fail on
masterand pass with the change. The full suite passes locally: 640 passed, 1 skipped. Black and ruff report nothing new in the touched files.I used Claude to help find this and draft the tests. I went through the change and ran the suite myself.