pydata / pydata/xarray

Request a warning for when coord names are ignored when dims are specified

Open
#11,234 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-error reporting
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What is your issue?

When coords are specified in tuple format, their names are silently ignored when dims names are also specified.

The following expression yields a DataArray that retains no reference to the otherwise specified coords of a, b, and c, in favor of the positionally-associated names of dims, x, y, and z.

DataArray(
    data=[[[1]], [[2]], [[3]]],
    dims=["x", "y", "z"],
    coords=[("a", [5, 6, 7]), ("b", [8]), ("c", [9])]
)

The result is:

<xarray.DataArray (x: 3, y: 1, z: 1)> Size: 24B
array([[[1]],
       [[2]],
       [[3]]])
Coordinates:
  * x        (x) int64 24B 5 6 7
  * y        (y) int64 8B 8
  * z        (z) int64 8B 9

Even though this behavior is documented, I think the user should be warned that the coordinate names do not match the dimension names and have been overridden.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the DataArray expression in the issue and trace the constructor path that handles tuple-form coords alongside explicit dims. Add a regression test for the mismatched names and verify that the resulting warning is emitted while the documented positional behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.