Skip to content

ux.open_dataset currently supports structured data #1854

Open

Description

@Sevans711

Version

v2026.10.0

How did you install UXarray?

Source

What happened?

ux.open_dataset() currently supports structured data (e.g. a lat/lon grid), silently returning a reasonable-looking answer. However, that is actually not intentional. For more details see: #1827 (comment).

What did you expect to happen?

Because opening structured data with ux.open_dataset() is not intended to be supported and is not currently being tested, uxarray should avoid silently returning a reasonable-looking answer which might actually be wrong. So, I would expect it to crash, or at least raise a warning, when pointed at structured data.

The crash or warning message should maybe point out that the UxDataset.from_structured() or UxDataset.from_xarray() could be considered instead, as the standard entry points for loading structured data into uxarray.

Can you provide a MCVE to repoduce the bug?

import numpy as np
import xarray as xr
import uxarray as ux

ds = xr.Dataset(
    {
        "t": (("time", "lat", "lon"), np.random.rand(2, 4, 8)),
        "s": (("lat", "lon"), np.random.rand(4, 8)),
        "z": (("time",), np.ones(2)),
    },
    coords={
        "lat": ("lat", np.linspace(-80, 80, 4), {"standard_name": "latitude"}),
        "lon": ("lon", np.linspace(0, 350, 8), {"standard_name": "longitude"}),
        "time": [0, 1],
    },
)

ux.open_dataset(ds, ds)  # grid, data
# silently returns a UxDataset with sizes {'time': 2, 'n_face': 32};
# I expected a crash or at least a warning, instead.

Activity

  1. erogluorhan commented on Oct 27, 2026

    @erogluorhan
    Member

    I wouldn't call this a bug; however, I believe that we should still avoid this to guide structured grid access through specialized API (from_structured()) only (I agree with ux.open_dataset() not being intended to support structured grids).

    I'd like to share what I was able to track about how this might have happened so far:

    To address the #725, #1043, and #1044 issues, PR #1040 was merged.

    Key detail: This PR didn't intend to open doors for open_dataset() to support structured grids (i.e. the only feature that was desired to be added was from_structured() for our objects. However, we didn't test calling open_dataset() directly on a structured grid/data either.

    Since this PR introduced _is_structured() as a fallback inside _parse_grid_type(), and it is shared across multiple APIs, and _map_dims_to_ugrid() has a "structured" branch, any CF-compliant structured dataset that doesn't match another grid spec gets silently, unintentionally, auto-detected and converted — through open_dataset()/open_grid() too.

    As emphasized, this was unintended and needs to be avoided because if the user accidentally uses it this way and sees it working for that case, it becomes misleading.

  2. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Oct 27, 2026
  3. Sevans711 commented on Nov 3, 2026

    @Sevans711
    CollaboratorAuthor

    Adding a quick note about something Orhan noticed during review of #1827. The new _map_dataset_to_ugrid(ds, grid) introduced these lines for supporting structured data:

        if grid.source_grid_spec == "Structured":
            lon_dim, lat_dim = source_dims["n_face"]
            if lon_dim not in ds.dims and lat_dim not in ds.dims:
                # No source spatial axes remain to flatten, including members
                # located only on canonical nodes or edges.
                return ds

    These lines weren't really necessary, but they also don't affect any tests using unstructured data, so that PR wasn't blocked on it. These lines should most likely be removed as part of fixing this issue / tightening ux.open_dataset() to no longer support structured data.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

Priority

Medium

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions