Skip to content

Namedarray generic dim type#11223

Draft
headtr1ck wants to merge 1 commit intopydata:mainfrom
headtr1ck:namedarray-generic-dims
Draft

Namedarray generic dim type#11223
headtr1ck wants to merge 1 commit intopydata:mainfrom
headtr1ck:namedarray-generic-dims

Conversation

@headtr1ck
Copy link
Collaborator

@headtr1ck headtr1ck commented Mar 10, 2026

This PR introduces a new Generic TypeVar for dimension names.
This hopefully removes some typing annoyances for 99% of the people that use only str dimension names.
Now NamedArray("x", [1, 2, 3]).dims is actually typed as tuple[str, ...] and not tuple[Hashable, ...] anymore :)

This is a breaking change for typing of NamedArray.

The type changes from NamedArray[ShapeType, DType] to NamedArray[ShapeType, DType, DimType]

Currently this only passes mypy -m xarray.namedarray.
Just wanted to see how much work it is to change that.

If it is decided that we want to go on with this change I will fix the rest of xarray and potentially create follow up PRs to propagate that change to DataArray and Dataset as well.

Note: I quick and dirty edited the _aggregations file. This has to be done more properly later...

@github-actions github-actions bot added topic-backends topic-indexing topic-cftime topic-zarr Related to zarr storage library topic-html-repr topic-DataTree Related to the implementation of a DataTree class io topic-NamedArray Lightweight version of Variable labels Mar 10, 2026
Also makes private typing names 'public' by removing leading _
@headtr1ck headtr1ck force-pushed the namedarray-generic-dims branch from a2d5512 to a96fc0a Compare March 10, 2026 21:54
@headtr1ck headtr1ck removed topic-backends topic-indexing topic-cftime topic-zarr Related to zarr storage library topic-html-repr topic-DataTree Related to the implementation of a DataTree class io labels Mar 11, 2026
@headtr1ck
Copy link
Collaborator Author

Are there any objections to this approach?

If not I will wrap this up and fix all remaining issues.

Next step is to incorporate the same changes into Variable in a follow up PR.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant