Skip to content

typing: add types to ndsl.stencils.testing.grid#404

Merged
romanc merged 3 commits into
NOAA-GFDL:developfrom
romanc:romanc/testing-grid
Mar 23, 2026
Merged

typing: add types to ndsl.stencils.testing.grid#404
romanc merged 3 commits into
NOAA-GFDL:developfrom
romanc:romanc/testing-grid

Conversation

@romanc
Copy link
Copy Markdown
Collaborator

@romanc romanc commented Mar 23, 2026

Description

Add type hints to the Grid class used in translate tests. This is not perfect, but at least we have now most types. Lots of magic happening here and if we don't have minimal type hint and type checking we'll missing things like the Quantity update in the first commit.

How has this been tested?

All good as long as CI is still green. Locally, mypy is happy.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. add new modules to docs/docstrings/): N/A
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules: N/A
  • New check tests, if applicable, are included

romanc added 3 commits March 23, 2026 11:01
These functions of the `Grid` class must be dead code because the
`Quantity` constructor now requires a backend argument (which isn't
provided). If anyone were to use that code, we'd see a type error.
Add type hints to the `Grid` class used in translate tests. This is not
perfect, but at least we have now most types. Lots of magic happening
here and if we don't have minimal type hint and type checking we'll
missing things like the `Quantity` update in the previous commit.
@romanc romanc marked this pull request as ready for review March 23, 2026 10:43
Comment on lines -167 to -200
def make_quantity(
self,
array,
dims=(I_DIM, J_DIM, K_DIM),
units="Unknown",
origin=None,
extent=None,
):
if origin is None:
origin = self.compute_origin()
if extent is None:
extent = self.domain_shape_compute()
return Quantity(array, dims=dims, units=units, origin=origin, extent=extent)

def quantity_dict_update(
self,
data_dict,
varname,
dims=(I_DIM, J_DIM, K_DIM),
units="Unknown",
):
data_dict[varname + "_quantity"] = self.quantity_wrap(
data_dict[varname], dims=dims, units=units
)

def quantity_wrap(
self,
data,
dims=(I_DIM, J_DIM, K_DIM),
units="unknown",
):
origin = self.sizer.get_origin(dims)
extent = self.sizer.get_extent(dims)
return Quantity(data, dims=dims, units=units, origin=origin, extent=extent)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Must be dead code because the Quantity constructor has a required backend argument. If we were still using these code paths, they'd be getting TypeErrors.

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.

Dead code for sure. Probably lined to translate system at some point to move toward a full quantity.

@romanc romanc requested a review from FlorianDeconinck March 23, 2026 10:46
Copy link
Copy Markdown
Collaborator

@FlorianDeconinck FlorianDeconinck left a comment

Choose a reason for hiding this comment

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

🧹

Having a stencils.testing.grid has been a vexing issue for a while but I am yet to take the time to nuke this monstrosity from orbit. I am yet to understand why we can't centralize the concept of grid and have this thing kicking around... Work for another time (sic).

@romanc romanc enabled auto-merge March 23, 2026 13:06
@romanc
Copy link
Copy Markdown
Collaborator Author

romanc commented Mar 23, 2026

yeah, I had a quick look why this class exists in the first place and very quickly stopped looking 🙈 Indeed it seems this has to be redundant (or at least just for convenience), but it seems to pull in a couple of concepts that I'm not yet super familiar with, so I just left it there. To be revisited later(tm)

@romanc romanc added this pull request to the merge queue Mar 23, 2026
Merged via the queue into NOAA-GFDL:develop with commit 469a58a Mar 23, 2026
7 of 8 checks passed
@romanc romanc deleted the romanc/testing-grid branch March 23, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants