html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/479#issuecomment-122484583,https://api.github.com/repos/pydata/xarray/issues/479,122484583,MDEyOklzc3VlQ29tbWVudDEyMjQ4NDU4Mw==,1217238,2015-07-18T05:15:40Z,2015-07-18T05:15:40Z,MEMBER,"I thought we were writing variables in order of appearance in datasets, but it looks like we weren't doing that. #480 should fix that issue, at least when using netCDF4-python (the default backend).

Once that patch is merged, you can reorder variables in datasets by indexing with a list of variable names, e.g.,

```
In [6]: ds = xray.Dataset(OrderedDict([('x', 10), ('a', -1), ('z', np.nan)]), {'c': 0})

In [7]: ds
Out[7]:
<xray.Dataset>
Dimensions:  ()
Coordinates:
    c        int64 0
Data variables:
    x        int64 10
    a        int64 -1
    z        float64 nan

In [9]: ds.to_netcdf('tmp.nc')

In [10]: ! ncdump -h tmp.nc
netcdf tmp {
variables:
    int64 x ;
    int64 a ;
    double z ;
    int64 c ;

// global attributes:
        :coordinates = ""c"" ;
}

In [11]: ds[['z', 'c', 'x', 'a']].to_netcdf('tmp.nc')

In [12]: ! ncdump -h tmp.nc
netcdf tmp {
variables:
    double z ;
    int64 c ;
    int64 x ;
    int64 a ;

// global attributes:
        :coordinates = ""c"" ;
}
```
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,95788263