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 116869436,MDU6SXNzdWUxMTY4Njk0MzY=,656,unexpected behavior when assignment used incorrectly,109530,closed,0,,,1,2015-11-13T22:51:12Z,2016-01-12T18:50:26Z,2016-01-12T18:50:26Z,NONE,,,,"An issue came up in which unexpected behavior was resulting from the use of the assignment operator with an `xray.Dataset`. You can see below in the first simple example, that an attribute can be created and attached to an `xray.Dataset` object, that the `xray` is not aware of: ``` python In [1]: import xray In [2]: ds = xray.Dataset() In [3]: ds.x = 1 In [4]: ds Out[4]: Dimensions: () Coordinates: *empty* Data variables: *empty* In [5]: ds.x Out[5]: 1 ``` It can be seen also in a bit more detail below, showing that one could easily mistake the assignment for doing something, when in fact it seems to do nothing to the expected variable: ``` python In [27]: ds = xray.Dataset( {'my_ones': (('dim1',), np.ones((100)))}, {'dim1':np.arange(0,100)}) In [28]: ds Out[28]: Dimensions: (dim1: 100) Coordinates: * dim1 (dim1) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Data variables: my_ones (dim1) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... In [29]: ds['new_var'] = np.random.rand(100) In [30]: ds Out[30]: Dimensions: (dim1: 100) Coordinates: * dim1 (dim1) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Data variables: my_ones (dim1) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... new_var (dim1) float64 0.008922 0.4298 0.878 0.3581 0.05668 0.4459 ... In [31]: ds.my_ones = np.random.rand(100) In [32]: ds Out[32]: Dimensions: (dim1: 100) Coordinates: * dim1 (dim1) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Data variables: my_ones (dim1) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... new_var (dim1) float64 0.008922 0.4298 0.878 0.3581 0.05668 0.4459 ... ``` See here, `my_ones` are still 1.0s even though we assigned them random numbers above! Now let's make a real attribute: ``` python In [33]: ds.attrs['my_real_attribute'] = ds.my_ones In [34]: ds Out[34]: Dimensions: (dim1: 100) Coordinates: * dim1 (dim1) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... Data variables: my_ones (dim1) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ... new_var (dim1) float64 0.008922 0.4298 0.878 0.3581 0.05668 0.4459 ... Attributes: my_real_attribute: [ 0.8999457 0.52066577 0.08915267 0.0541855 0.45131377 0.09501768 0.95209237 0.89464241 0.36151148 0.10759526 0.91542506 0.22980835 0.17357796 0.19259669 0.17985614 0.20401482 0.46921508 0.27108936 0.2420025 0.75083791 0.94271824 0.89902967 0.29649179 0.70362153 0.73475068 0.3591411 0.79941874 0.18079561 0.23058618 0.84660496 0.82993496 0.50236557 0.09758405 0.82851117 0.85434362 0.33170515 0.11670085 0.37135022 0.8647876 0.18162848 0.5675491... ``` And we see it shows up. Somehow `ds.my_ones` persists, but it is not an attribute and not in fact a variable... strange! ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/656/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue