Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTree repr showing inherited coordinates as non-inherited #9499

Closed
TomNicholas opened this issue Sep 15, 2024 · 1 comment · Fixed by #9532
Closed

DataTree repr showing inherited coordinates as non-inherited #9499

TomNicholas opened this issue Sep 15, 2024 · 1 comment · Fixed by #9532
Labels
bug topic-DataTree Related to the implementation of a DataTree class topic-documentation

Comments

@TomNicholas
Copy link
Member

TomNicholas commented Sep 15, 2024

What is your issue?

The example DataTree under "DataTree Inheritance" on the Data Structures docs page doesn't display the way I expected it to.

It currently looks like this:

Out[104]: 
<xarray.DataTree>
Group: /Dimensions:  (time: 2)
│   Coordinates:
│     * time     (time) <U7 56B '2022-01' '2023-01'
├── Group: /weather
│   │   Dimensions:     (station: 6, time: 2)
│   │   Coordinates:
│   │     * time        (time) <U7 56B '2022-01' '2023-01'
│   │     * station     (station) <U1 24B 'a' 'b' 'c' 'd' 'e' 'f'
│   │   Data variables:
│   │       wind_speed  (time, station) float64 96B 2.0 2.0 2.0 2.0 ... 2.0 2.0 2.0 2.0
│   │       pressure    (time, station) float64 96B 3.0 3.0 3.0 3.0 ... 3.0 3.0 3.0 3.0
│   └── Group: /weather/temperatureDimensions:          (time: 2, station: 6)
│           Data variables:
│               air_temperature  (time, station) float64 96B 4.0 4.0 4.0 4.0 ... 4.0 4.0 4.0dewpoint         (time, station) float64 96B 5.0 5.0 5.0 5.0 ... 5.0 5.0 5.0
└── Group: /satellite
        Dimensions:     (lat: 3, lon: 3, time: 2)
        Coordinates:
          * time        (time) <U7 56B '2022-01' '2023-01'
          * lat         (lat) int64 24B 10 20 30
          * lon         (lon) int64 24B -100 -80 -60
        Data variables:
            infrared    (time, lon, lat) float64 144B 6.0 6.0 6.0 6.0 ... 6.0 6.0 6.0
            true_color  (time, lon, lat) float64 144B 7.0 7.0 7.0 7.0 ... 7.0 7.0 7.0

Which notice has an identical time coordinate displayed in multiple child groups.

But I expected it to look like this:

Out[104]: 
<xarray.DataTree>
Group: /Dimensions:  (time: 2)
│   Coordinates:
│     * time     (time) <U7 56B '2022-01' '2023-01'
├── Group: /weather
│   │   Dimensions:     (station: 6, time: 2)
│   │   Coordinates:
│   │     * station     (station) <U1 24B 'a' 'b' 'c' 'd' 'e' 'f'
│   │   Data variables:
│   │       wind_speed  (time, station) float64 96B 2.0 2.0 2.0 2.0 ... 2.0 2.0 2.0 2.0
│   │       pressure    (time, station) float64 96B 3.0 3.0 3.0 3.0 ... 3.0 3.0 3.0 3.0
│   └── Group: /weather/temperatureDimensions:          (time: 2, station: 6)
│           Data variables:
│               air_temperature  (time, station) float64 96B 4.0 4.0 4.0 4.0 ... 4.0 4.0 4.0dewpoint         (time, station) float64 96B 5.0 5.0 5.0 5.0 ... 5.0 5.0 5.0
└── Group: /satellite
        Dimensions:     (lat: 3, lon: 3, time: 2)
        Coordinates:
          * lat         (lat) int64 24B 10 20 30
          * lon         (lon) int64 24B -100 -80 -60
        Data variables:
            infrared    (time, lon, lat) float64 144B 6.0 6.0 6.0 6.0 ... 6.0 6.0 6.0
            true_color  (time, lon, lat) float64 144B 7.0 7.0 7.0 7.0 ... 7.0 7.0 7.0

which only has time defined in the root group. Based on #9463 I expected the inheritance onto child node to be implicit, and not have the same coordinate explicitly displayed twice.

I also don't understand why the current repr does not have time displayed in the /weather/temperature node.

It's possible that this is caused by an interaction between #9475 and .from_dict (I haven't looked into this deeply yet), but I wanted to make a note that we should come back to check this definitely works once #9475 is resolved.

cc @shoyer @flamingbear

@TomNicholas TomNicholas added bug topic-documentation topic-DataTree Related to the implementation of a DataTree class labels Sep 15, 2024
@shoyer
Copy link
Member

shoyer commented Sep 17, 2024

Indeed, something is definitely going wrong in the from_dict constructor.

Looks at what dt['weather'] looks like -- it's even worse, with a duplicate "time" coordinate!

In [7]: dt2['weather']
Out[7]:
<xarray.DataTree 'weather'>
Group: /weather
│   Dimensions:     (time: 2, station: 6)
│   Coordinates:
│     * time        (time) <U7 56B '2022-01' '2023-01'
│     * station     (station) <U1 24B 'a' 'b' 'c' 'd' 'e' 'f'
│   Inherited coordinates:
│     * time        (time) <U7 56B '2022-01' '2023-01'
│   Data variables:
│       wind_speed  (time, station) float64 96B 2.0 2.0 2.0 2.0 ... 2.0 2.0 2.0 2.0
│       pressure    (time, station) float64 96B 3.0 3.0 3.0 3.0 ... 3.0 3.0 3.0 3.0
└── Group: /weather/temperature
        Dimensions:          (time: 2, station: 6)
        Data variables:
            air_temperature  (time, station) float64 96B 4.0 4.0 4.0 4.0 ... 4.0 4.0 4.0
            dewpoint         (time, station) float64 96B 5.0 5.0 5.0 5.0 ... 5.0 5.0 5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug topic-DataTree Related to the implementation of a DataTree class topic-documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants