Skip to content

Add invariant check for IndexVariable.name - #8906

Draft
dcherian wants to merge 5 commits into
pydata:mainfrom
dcherian:add-invariant
Draft

Add invariant check for IndexVariable.name#8906
dcherian wants to merge 5 commits into
pydata:mainfrom
dcherian:add-invariant

Conversation

@dcherian

Copy link
Copy Markdown
Contributor

@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
dcherian requested a review from benbovyApril 4, 2024 02:13
@dcheriandcherian changed the title Add invariant check for #8646Add invariant check for IndexVariable.nameApr 4, 2024
@benbovy

Copy link
Copy Markdown
Member

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!).

"""

__slots__ = ()
__slots__ = ("_name",)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the name property instead or is that much much harder?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better indeed but this is likely more work (not sure how much, though).

IndexVariable still needs a deeper refactor (#8124), or even be eventually dropped?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the .name property used?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a quick check: internally only in a few places (conventions / multiindex check, dataarray creation, maybe groupby?) actually.

Externally I have no idea (IndexVariable is public API in theory).

@dcherian

Copy link
Copy Markdown
ContributorAuthor

Here's a wilder idea:

@property.getterdefname(self) ->Hashable:
name, =self._dimsreturnname@property.setterdefname(self):
# maybe warn for a while firstraiseNotImplementedError

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

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants

@dcherian@benbovy