xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Forbid pathlike DataTree coordinate names

Open eshort0401 opened this issue 2 months ago • 0 comments

  • [x] Prevents reaching state described in #9485
  • [x] Tests added
  • [x] User visible changes (including notable bug fixes) are documented in whats-new.rst

Forbids pathlike coordinate names as a temporary solution before #9485 is fully resolved. This PR is almost the same as the coordinate name checking part of @TomNicholas's PR #9492 from 2024; not sure why this wasn't merged, and happy to update whats-new.rst authorship if appropriate! The main difference between this PR and #9492 is a targeted error message when coordinate keys are being checked. Code like

from xarray import DataTree, Dataset
tree = DataTree(Dataset(coords={'x': 0}), children={'child': DataTree()})
tree.coords['/child/y'] = 2

will now produce

ValueError: Given coordinate names contain the '/' character: ['/child/y']. Accessing the coordinates of other nodes in the tree is not yet supported here. Retrieve the other node first, then access its coordinates.

I've also amended the DataTree.coords and DataTree.data_vars docstrings to communicate these currently only access the coordinates and variables of the given node, respectively.

Notes

This PR follows from discussion in #11001.

eshort0401 avatar Dec 15 '25 01:12 eshort0401