Skip to content

Add more Dataset methods/properties to uxarray.Grid #1647

Closed as not planned
Closed as not planned

Description

@Sevans711

Proposed new feature or change:

uxarray.Grid objects behave mostly like xarray.Datasets, but with some additional fancier behavior related to unstructured grids. They even display similarly to how Dataset objects display! So, I have come to expect/want all relevant Dataset-like behaviors to apply to Grids, too.

Examples of code I expected to work on Grids which currently does not work:

  1. grid.get("node_lon"), grid.keys() and other dict-like behaviors
  2. grid.identical(other_grid)
  3. grid.nbytes (relevant: ASV better memory benchmarks #1609 (comment)) as well as other attributes like grid.coords, grid.data_vars, grid.dtypes
  4. grid.compute() and other dask-related methods, in case some of the underlying data is chunked

Examples of code which should maybe work on Grids but which currently does not work:

  1. grid.roll(n_node=10) -- I would think this should probably roll along the n_node dimension and maybe renumber nodes as needed? But, it's a bit ambiguous.
  2. grid.rename(extra_var='newname') -- should probably return a new grid with extra_var renamed accordingly, if it isn't one of the core names for grids (like "node_lon" or "n_face"). This assumes Grid objects continue to support extra variables when present (e.g. when the input file contains non-grid-data, maybe something like "custom_node_labels" containing string labels for each node, in a small grid).
  3. grid.isnull() could probably be allowed?

Examples of code which should continue to not be supported on Grids:

  1. grid.mean() as well as min, max, std, and other statistics which don't really make sense to apply to a Grid
  2. grid.interp(...) probably wouldn't really make sense
  3. grid.integrate() and any other math functions which don't really make sense to apply across all data variables within a Grid

A 100% complete solution to this issue would require considering every single method and attribute supported by xarray.Dataset, deciding whether they should be supported by Grid, and implementing if needed.

That would probably be way too much to review within a single PR. On the other hand, it could get unwieldy to handle too many tiny PRs each implementing only a single new method or attribute, especially when the implementations are as simple as simply calling the corresponding method from the underlying grid._ds. My suggestion would be to instead create a few PRs which each form reasonably-natural groupings. For example, one PR might try something like "implements dict-like behaviors for Grids: get(), keys(), items(), ..." while another might do "adds Dataset-like attributes for Grids: nbytes, coords, data_vars, chunks, dtypes, ...". Each of them would address part of this issue. Comments in thread on this issue could be used to track a more exhaustive list of available Dataset methods and discussion about whether they should be implemented for Grid.

Activity

  1. added
    new featureNew user-facing functionality
    improvementImprovements on existing features or infrastructure
    on Aug 4, 2026
  2. added
    designDesign of an API, feature, or user interface (not just implementation details)
    on Aug 11, 2026
  3. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Aug 13, 2026
  4. moved this from 📝 To-Do to 📚 Backlog in UXarray Developmenton Aug 17, 2026
  5. erogluorhan commented on Aug 18, 2026

    @erogluorhan
    Member

    Thanks very much for considering this @Sevans711 !

    I don't agree that they currently mostly behave or should increasingly behave like Datasets though:

    • Accessing grids through UxDataset.uxgrid and UxDataArray.uxgrid in most cases (i.e. unless Grid lieves standalone) should give the indication that grids are rather properties of datasets.
    • Overwhelming majority of properties and functions of Grid and UxDataset are distinct from each other by both design and the driving use cases.
    • There are several places in our docs that clearly distinguish Grid and UxDataset (e.g. Data structures, API reference
    • Even though some of the usages might feel similar (e.g. display), they are there for providing familiar user experience in media like Jupyter notebooks and probably minority of the API.

    All that said, this is a big lift, and I am not sure if we should go this route with its entirety (there might be need for individual things, and hearing scientific workflows to see if there is actual need for them might be useful, e.g. renaming a grid, etc.)

  6. moved this from 📚 Backlog to No plans for now in UXarray Developmenton Aug 18, 2026
  7. Sevans711 commented on Aug 18, 2026

    @Sevans711
    CollaboratorAuthor

    Quick clarifications/followups:

    • Clarifying: I definitely agree that Grid and UxDataset are very different, and I think the docs do a good job distinguishing between them. Above I was instead attempting to say that Grid feels like a specialized xarray.Dataset (not UxDataset). This is primarily because its main purposes seem to be (dataset-like) bookkeeping for dimensions and coordinates and (specialized) handling unstructured grid functionality. The underlying Grid data also seems to be primarily stored in .nc files, which I understand as mapping naturally into xarray Datasets.
    • (From internal discussion) we are on the same page that this work should be low priority overall (with the understanding that UXarray users do not often prioritize Grid introspection).
    • (From internal discussion) we were also on the same page that some particular pieces might be slightly higher priority, perhaps perhaps grid.nbytes and grid.compute(). We discussed that it might be a good idea to make separate sub-issues for those pieces, especially if any user workflow would need them directly.
  8. added
    may revisitClosed as not planned for now, but may revisit at some point in the future
    on Aug 18, 2026
  9. erogluorhan commented on Aug 18, 2026

    @erogluorhan
    Member

    Quick clarifications/followups:

    • Clarifying: I definitely agree that Grid and UxDataset are very different, and I think the docs do a good job distinguishing between them. Above I was instead attempting to say that Grid feels like a specialized xarray.Dataset (not UxDataset). This is primarily because its main purposes seem to be (dataset-like) bookkeeping for dimensions and coordinates and (specialized) handling unstructured grid functionality. The underlying Grid data also seems to be primarily stored in .nc files, which I understand as mapping naturally into xarray Datasets.

    100%. Thanks for clarifying! The Grid object has a xr.Dataset (i.e. composition) to handle all that you mentioned above, and the similarity feeling comes from that I believe.

    • (From internal discussion) we are on the same page that this work should be low priority overall (with the understanding that UXarray users do not often prioritize Grid introspection).
    • (From internal discussion) we were also on the same page that some particular pieces might be slightly higher priority, perhaps perhaps grid.nbytes and grid.compute(). We discussed that it might be a good idea to make separate sub-issues for those pieces, especially if any user workflow would need them directly.

    Agreed. Let's even go further and close this overarching issue that has too many points that may or may not be voted for implementation, and when the time comes, rather open individual issue(s) for only corresponding task. e.g. issue for grid.compute().

    I've added a May Revisit label for this to help with future issues.

  10. moved this from No plans for now to ✅ Done in UXarray Developmenton Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    designDesign of an API, feature, or user interface (not just implementation details)improvementImprovements on existing features or infrastructuremay revisitClosed as not planned for now, but may revisit at some point in the futurenew featureNew user-facing functionality

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions