issues: 574015429
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
574015429 | MDU6SXNzdWU1NzQwMTU0Mjk= | 3819 | expand_dims changes attrs and encoding of coordinate variable | 11731042 | closed | 0 | 3 | 2020-03-02T14:33:30Z | 2020-07-02T22:00:03Z | 2020-07-02T22:00:02Z | NONE | Expanding the dimensions of a variable with a dimension having the same name as a coordinate variable will also change the attributes (including encoding attributes) of this coordinate variable! The following examples prints the attrs and encoding of coordinate variable ```python import xarray as xr import numpy as np grid = xr.Dataset({ 'time': (('time',), [np.datetime64('2018-01-01')]), 'lat': (('lat'), np.arange(-80, 80, 1)), 'lon': (('lon',), np.arange(-180, 180, 1)), 'sea_surface_temperature': (('lat', 'lon',), np.ones(shape=(160, 360))) }) grid['time'].encoding['units'] = 'seconds since 1981-01-01 00:00:00' grid['time'].attrs['comment'] = 'some comment' print(grid['time'].encoding, grid['time'].attrs) grid['sea_surface_temperature'] = grid['sea_surface_temperature'].expand_dims('time', axis=0) print(grid['time'].encoding, grid['time'].attrs) ``` The current output is:
Expected OutputI would not expect any change to other coordinates or variables than the expanded one (here
Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/3819/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |