Repository navigation
Conversation
The public grid-loading APIs document and implement use_dual as a boolean, but their annotations also accepted None. Align the public and internal signatures with the actual contract and add focused regression coverage.
Sevans711
left a comment
There was a problem hiding this comment.
Regarding None type hints, these were fully solved by #1862, and I don't see any changes here related to that at all, aside from creating test/core/test_type_hints.py. Please update the title and PR description accordingly, and please remove test/core/test_type_hints.py from this PR, as it is entirely unrelated to docstring examples. If you believe those tests should be added into main, please put them into a separate issue report and PR with corresponding scope.
This PR's scope also appears insufficient to close #1611, which requests adding new examples as well as running existing examples. I would recommend either re-scoping that issue to just request running existing examples, or opening a sub-issue with that scope and linking this PR as closing that sub-issue instead.
Additionally, too many tests are being skipped here which can probably easily be rewritten to use files we do ship. Please rewrite them accordingly. If there are any cases remaining which absolutely must be skipped because there aren't any relevant easy-to-reach example files, please explain them on a case-by-case basis in the PR description to make them easier to understand and review. I've added a few inline comments about this, but I didn't highlight every skip directly.
| Access the integral of a single variable | ||
|
|
||
| >>> integral["psi"] | ||
| >>> round(float(integral["psi"]), 4) |
There was a problem hiding this comment.
I understand this as a way to ensure the output is exactly 12.5664, so that doctest can match the expected output. But, it does make this example less human-readable, as the concept has shifted from a simple "index the result to get the value for a single variable" to "round, convert to float, and index the result to get the value for a single variable". Please clarify in the example somewhere, or find a way to keep doctest happy while restoring a more concise syntax for this part to keep it easy to read for humans.
There was a problem hiding this comment.
Changed in b42e5ee to float(integral["psi"]) with the NUMBER directive, so it reads plainly and still fails on a wrong value. The plain DataArray repr includes attrs and coords, so it's brittle as expected output.
There was a problem hiding this comment.
Minor nit (non-blocking), could you swap to integral["psi"].item() instead? I see arr.item() as the "canonical" way to convert from a scalar xarray DataArray into a single number, moreso than float() because float() requires you to know the expected dtype ahead of time but .item() does not.
Aside from that this point is resolved, thank you!
|
Thanks @Sevans711. I dropped the type hint test and the None scope (done in #1862), replaced every SKIP with tutorial data or shipped meshfiles, and changed the link to Part of #1611 since new examples for other functions are still open there. Each inline comment has a reply with the commit that addresses it. |
Sevans711
left a comment
There was a problem hiding this comment.
Happy to approve this one, my previous points have all been addressed, and the PR overview message has been updated appropriately for more context and to avoid fully closing #1611. I have a few remaining points tracked in inline comments, but they don't need to block this PR if it is otherwise ready to merge.
| Reuse one grid for two data files containing different variables | ||
|
|
||
| >>> uxgrid = ux.open_grid("grid_file.nc") # doctest: +SKIP | ||
| >>> member_1 = ux.open_dataset(uxgrid, "member_1.nc") # doctest: +SKIP | ||
| >>> member_2 = ux.open_dataset(uxgrid, "member_2.nc") # doctest: +SKIP | ||
| >>> member_1.uxgrid is member_2.uxgrid # doctest: +SKIP | ||
| >>> uxgrid = ux.open_grid(grid_path) | ||
| >>> other_path = "test/meshfiles/ugrid/outCSne30/outCSne30_var2.nc" | ||
| >>> vortex = ux.open_dataset(uxgrid, data_path) | ||
| >>> other = ux.open_dataset(uxgrid, other_path) | ||
| >>> vortex.uxgrid is other.uxgrid |
There was a problem hiding this comment.
Please update so that this is a standalone example, instead of re-using the grid_path and data_path variables from above. I know that the doctest CI can re-use them, but the way the docstring is written here it really feels like each example is intended to be self contained. EDIT: alternatively, define all paths at the start and then put example numbers to suggest it is a continuous workflow, as was done for open_mfdataset below.
Also a minor style point, please consider putting the path strings before the open_grid call; workflows are slightly easier to parse when it's clearly (1) imports, (2) define paths and constants, (3) run code, instead of swapping back and forth between (2) and (3).
| Access the integral of a single variable | ||
|
|
||
| >>> integral["psi"] | ||
| >>> round(float(integral["psi"]), 4) |
There was a problem hiding this comment.
Minor nit (non-blocking), could you swap to integral["psi"].item() instead? I see arr.item() as the "canonical" way to convert from a scalar xarray DataArray into a single number, moreso than float() because float() requires you to know the expected dtype ahead of time but .item() does not.
Aside from that this point is resolved, thank you!
Part of #1611; follow-up for the remaining modules is #1920.
Overview
Examples in
api.py,dataarray.py,dataset.pyandgrid.pynow use tutorial data or shipped meshfiles, and CI runs them with--doctest-modules. Also fixes therhint inKDTree.query_radiusandBallTree.query_radiusfrominttofloat, since the default is1.0.PR Checklist
General
Testing & Benchmarking
Documentation and Examples
docs/api.rstAI Disclosure
AI Usage: Claude Code