Skip to content

Conversation

@ahijevyc
Copy link
Collaborator

@ahijevyc ahijevyc commented Aug 6, 2025

Closes #1332

Maybe related to issue #1189

Avoid xarray UserWarnings like

uxarray/lib/python3.12/site-packages/xarray/namedarray/core.py:503: UserWarning: Duplicate dimension names present: dimensions {'two'} appear more than once in dims=('n_face', 'two', 'two'). We do not yet support duplicate dimension names, but we do allow initial construction of the object. We recommend you rename the dims immediately to become distinct, as most xarray functionality is likely to fail silently if you do not. To rename the dimensions you will need to set the ``.dims`` attribute of each variable, ``e.g. var.dims=('x0', 'x1')``.
  self._dims = self._parse_dimensions(value)
/glade/work/ahijevyc/conda-envs/uxarray/lib/python3.12/site-packages/xarray/namedarray/core.py:264: UserWarning: Duplicate dimension names present: dimensions {'two'} appear more than once in dims=('n_face', 'two', 'two'). We do not yet support duplicate dimension names, but we do allow initial construction of the object. We recommend you rename the dims immediately to become distinct, as most xarray functionality is likely to fail silently if you do not. To rename the dimensions you will need to set the ``.dims`` attribute of each variable, ``e.g. var.dims=('x0', 'x1')``.
  self._dims = self._parse_dimensions(dims)

Overview

Don't rename size-2 dimensions in io/_ugrid.py.

The original renaming logic might reflect MPAS's convention of naming dimensions of size 2 'TWO'. While this assumption may hold for MPAS-generated files, it causes dimension name collisions when reading other valid UGRID-compliant files (e.g., SCRIP) that use multiple, descriptively-named dimensions of size 2, like lon_lat and min_max.

PR Checklist

General

  • An issue is linked created and linked
  • Add appropriate labels
  • Filled out Overview and Expected Usage (if applicable) sections

Testing

  • Adequate tests are created if there is new functionality
  • [N/A] Tests cover all possible logical paths in your function
  • [N/A] Tests are not too basic (such as simply calling a function and nothing else)

@ahijevyc ahijevyc added the bug Something isn't working label Aug 6, 2025
@philipc2
Copy link
Member

philipc2 commented Aug 6, 2025

Thanks for putting this together! I've noticed this on occasion.

@ahijevyc ahijevyc marked this pull request as ready for review August 6, 2025 19:00
@ahijevyc ahijevyc requested a review from philipc2 August 6, 2025 19:00
@rajeeja rajeeja merged commit 9a4a1d1 into UXARRAY:main Aug 7, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

open_dataset incorrectly renames dimensions of size 2, causing duplicate dimension names

3 participants