xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Add invariant check for IndexVariable.name

Open dcherian opened this issue 1 year ago • 2 comments

@benbovy this seems to be the root cause of #8646, the variable name in Dataset._variables does not match IndexVariable.name.

A good number of tests seem to fail though, so not sure if this is a good chck.

  • [ ] Closes #xxxx
  • [ ] Tests added
  • [ ] User visible changes (including notable bug fixes) are documented in whats-new.rst
  • [ ] New functions/methods are listed in api.rst

dcherian avatar Apr 04 '24 02:04 dcherian

Thanks @dcherian, that's a good check to have I think. Most (if not all?) errors seem to be multi-index level variables that wrongly have their dimension name set as IndexVariable .name. I haven't looked into it yet but there might probably be an easy fix (hopefully!).

benbovy avatar Apr 04 '24 11:04 benbovy

Here's a wilder idea:

@property.getter
def name(self) -> Hashable:
    name, = self._dims
    return name

@property.setter
def name(self):
    # maybe warn for a while first
    raise NotImplementedError

dcherian avatar Jun 14 '24 17:06 dcherian