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

Broadcasting dimensions with xr.Dataset #76

Open
nicrie opened this issue Aug 11, 2023 · 0 comments
Open

Broadcasting dimensions with xr.Dataset #76

nicrie opened this issue Aug 11, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@nicrie
Copy link
Collaborator

nicrie commented Aug 11, 2023

Combining xr.Dataset as input with both multi-dimensional sample and feature dimensions will broadcast dimensions thus yielding components with inflated dimensions. The broadcasted dimensions are filled with NaN and results seem right. ideally, however, this broadcasting shouldn't happen and should be avoided.

In a nutshell, instead of obtaining components like the following

xarray.Dataset
    Dimensions: (sample1: 2, feature1: 2, feature2: 3)
    Coordinates:  
        sample1  (sample1)  int64  1 2
        feature1  (feature1)  <U1  'a' 'b'
        feature2  (feature2)  int64  0 1 2
    Data variables:
        da1  (sample1, feature1, feature2)   int64    0 1 2 3 4 5 6 7 8 9 10 11
        da2  (sample1, feature1)   int64    0 3 6 9
    Indexes: (3)
    Attributes: (0)

we currently get

xarray.Dataset
    Dimensions: sample1: 2,  feature1: 2,  feature2: 3
    Coordinates:
        sample1 (sample1)  int64 1 2
        feature1 (feature1)   <U1  'a' 'b'
        feature2 (feature2)  int  0 1 2
    Data variables:
        da1  (sample1, feature1, feature2)  int64   0 1 nan 3 ... 9 10 nan
        da2  (sample1, feature1, feature2)  int64   nan nan 0 nan ... 6 nan nan 9
    Indexes: (3)
    Attributes: (0)

This arises from a potential inconsistency in xarray's to_stacked_array()/to_unstacked_dataset() methods (see discussion).

@nicrie nicrie added the bug Something isn't working label Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant