Skip to content

Run core docstring examples in CI - #1859

Open
rajeeja wants to merge 10 commits into
mainfrom
rajeeja/doctest-type-hints
Open

rajeeja wants to merge 10 commits into
mainfrom
rajeeja/doctest-type-hints

Conversation

@rajeeja

@rajeeja rajeeja commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1611; follow-up for the remaining modules is #1920.

Overview

Examples in api.py, dataarray.py, dataset.py and grid.py now use tutorial data or shipped meshfiles, and CI runs them with --doctest-modules. Also fixes the r hint in KDTree.query_radius and BallTree.query_radius from int to float, since the default is 1.0.

PR Checklist

General

  • An issue is created and linked
  • Filled out Overview

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR
  • [N/A] If this PR could affect performance, ran ASV benchmarks

Documentation and Examples

  • Docstrings updated with any function changes
  • [N/A] User (public) functions added to docs/api.rst

AI Disclosure

AI Usage: Claude Code

  • I have tested and take responsibility for all AI-generated content in my PR.

Sanjays2402 and others added 3 commits October 28, 2026 15:51
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.
@rajeeja rajeeja added documentation Improvements or additions to documentation CI Continuous Integration labels Oct 28, 2026
@cmdupuis3
cmdupuis3 self-requested a review October 28, 2026 21:26
@rajeeja
rajeeja marked this pull request as draft October 29, 2026 12:11
@rajeeja
rajeeja marked this pull request as ready for review November 3, 2026 21:50
@rajeeja
rajeeja requested a review from Sevans711 November 3, 2026 21:50

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread .github/workflows/ci.yml Resolved
Comment thread uxarray/core/api.py Resolved
Comment thread uxarray/core/api.py Resolved
Comment thread uxarray/core/api.py Resolved
Comment thread uxarray/core/api.py Resolved
Comment thread uxarray/core/dataset.py Outdated
Access the integral of a single variable

>>> integral["psi"]
>>> round(float(integral["psi"]), 4)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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!

Comment thread uxarray/grid/neighbors.py Resolved
@rajeeja
rajeeja requested a review from Sevans711 November 5, 2026 19:38
@rajeeja rajeeja changed the title Run docstring examples in CI and tighten None type hints Run core docstring examples in CI Nov 24, 2026
@rajeeja

rajeeja commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

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 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread uxarray/core/api.py
Comment on lines +483 to +489
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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).

Comment thread uxarray/core/dataset.py Outdated
Access the integral of a single variable

>>> integral["psi"]
>>> round(float(integral["psi"]), 4)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants