Skip to content

open_datatree(group='some_subgroup') returning parent nodes #9665

Closed
@eni-awowale

Description

@eni-awowale

What is your issue?

@aladinor Noticed this during a demo a few meetings back but I don't think we followed up on this.

If you have a DataTree of this shape.

<xarray.DataTree>
Group: /
│   Dimensions:        (lat: 1, lon: 2)
│   Dimensions without coordinates: lat, lon
│   Data variables:
│       root_variable  (lat, lon) float64 16B ...
└── Group: /Group1
    │   Dimensions:      (lat: 1, lon: 2)
    │   Dimensions without coordinates: lat, lon
    │   Data variables:
    │       group_1_var  (lat, lon) float64 16B ...
    └── Group: /Group1/subgroup1
            Dimensions:        (lat: 1, lon: 2)
            Dimensions without coordinates: lat, lon
            Data variables:
                subgroup1_var  (lat, lon) float64 16B ...

And you specify a path with group= you still get a nested tree but with empty groups for the groups that were not specified.

In  [1]: open_datatree('filename.nc', engine='netcdf4', group='/Group1/subgroup')
Out [1]: 
<xarray.DataTree>
Group: /
└── Group: /Group1
    └── Group: /Group1/subgroup1
            Dimensions:        (lat: 1, lon: 2)
            Dimensions without coordinates: lat, lon
            Data variables:
                subgroup1_var  (lat, lon) float64 16B ...

I thought the expected result would be to only return the group specified with all of it's child nodes (if it has any), something like:

<xarray.DataTree>
Group: /Group1/subgroup1
            Dimensions:        (lat: 1, lon: 2)
            Dimensions without coordinates: lat, lon
            Data variables:
                subgroup1_var  (lat, lon) float64 16B ...

CCing the usual squad @shoyer, @keewis, @TomNicholas, @owenlittlejohns, and @flamingbear

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions