You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ux.open_dataset currently supports structured data #1854
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?
importnumpyasnpimportxarrayasxrimportuxarrayasuxds=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.
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:
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.
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:
ifgrid.source_grid_spec=="Structured":
lon_dim, lat_dim=source_dims["n_face"]
iflon_dimnotinds.dimsandlat_dimnotinds.dims:
# No source spatial axes remain to flatten, including members# located only on canonical nodes or edges.returnds
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.
Activity
erogluorhan commentedon Oct 27, 2026
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 withux.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 wasfrom_structured()for our objects. However, we didn't test callingopen_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 — throughopen_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.
Sevans711 commentedon Nov 3, 2026
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: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.