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

ds.rolling() drops attributes and name #4497

Closed
ALDepp opened this issue Oct 9, 2020 · 1 comment · Fixed by #4510
Closed

ds.rolling() drops attributes and name #4497

ALDepp opened this issue Oct 9, 2020 · 1 comment · Fixed by #4510
Labels
topic-metadata Relating to the handling of metadata (i.e. attrs and encoding)

Comments

@ALDepp
Copy link

ALDepp commented Oct 9, 2020

Hi all,

I just played around with some data and found that xarray's "rolling" drops the attributes and name (even if I say keep_attrs=True):

nt, nx = 100, 30
da = xr.DataArray(np.random.randn(nt, nx), dims=['time', 'x'],
                  name='foo') 
da.attrs['place'] = 'here'
da.attrs['long_name'] = 'test'

da
xarray.DataArray'foo'time: 100x: 30
array([[ 0.14720402, -0.29625209, -0.13164254, ...,  0.58363874,
         0.20588748,  1.21594309],
       [ 1.23770654, -0.18156258,  0.9182397 , ...,  0.16810624,
        -0.40726509,  0.2328856 ],
       [-0.10127142,  0.55696125,  0.7765333 , ..., -1.24054728,
        -0.3520287 ,  0.34090885],
       ...,
       [-0.62290589,  0.95234302,  1.33738597, ...,  1.25784705,
         0.32367764,  1.7907127 ],
       [ 0.2987966 , -0.9820949 , -1.33291223, ..., -0.43975905,
         2.28465498,  0.43231269],
       [ 0.66635482,  0.74084712, -2.02589549, ...,  1.64077719,
         2.84362149, -0.36572597]])
Coordinates: (0)
Attributes:
place : here
long_name : test

da.rolling(time=5).mean(dim='time')
xarray.DataArraytime: 100x: 30
array([[        nan,         nan,         nan, ...,         nan,
                nan,         nan],
       [        nan,         nan,         nan, ...,         nan,
                nan,         nan],
       [        nan,         nan,         nan, ...,         nan,
                nan,         nan],
       ...,
       [-0.56217953,  0.73100328,  0.03839124, ...,  0.60660493,
        -0.22207041,  0.72327949],
       [-0.31968275,  0.52925981,  0.00241698, ...,  0.70700785,
         0.34605282,  0.69566641],
       [-0.15442784,  0.78247162, -0.017953  , ...,  0.75334648,
         1.03670267,  0.89595308]])
Coordinates: (0)
Attributes: (0)

Again, this also happens when I include keep_attrs=True at both steps, rolling and mean. I think it should keep the name and attributes?

@dcherian dcherian added the topic-metadata Relating to the handling of metadata (i.e. attrs and encoding) label Oct 9, 2020
@mathause
Copy link
Collaborator

Yes, keep_attrs would only apply to global attrs of Datasets. See #4510 for a potential fix. I only just saw that you also mention the name this is not yet included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-metadata Relating to the handling of metadata (i.e. attrs and encoding)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants