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 818266159,MDU6SXNzdWU4MTgyNjYxNTk=,4973,NetCDF encoded data not automatically decoded back into original dtype,625462,closed,0,,,2,2021-02-28T17:57:33Z,2022-04-09T01:41:22Z,2022-04-09T01:41:22Z,NONE,,,,"**What happened**: When reading in an encoded netCDF4 file, encoded variables are not transformed back to their original dtype in the resulting xarray. **What you expected to happen**: As with the raw netCDF4 package, if an `xarray.DataArray` of dtype `float64` is encoded into a netCDF4 file as a `float32`, it should be converted back to the original `float64` when the netCDF4 dataset is read back in. **Minimal Complete Verifiable Example**: ```python import xarray as xr import numpy as np foo = xr.DataArray(np.random.uniform(size=[100,100]).astype(np.float64)) foo.dtype # float64 ds = xr.Dataset({'foo': foo}) ds.to_netcdf(""foo.nc"", encoding={'foo': {'dtype': 'float32', 'scale_factor': 1.0, 'add_offset': 0.0}}) ds1 = xr.open_dataset(""foo.nc"") ds1['foo'].dtype # float32, not float64 as expected ``` **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.7.7 (default, Mar 23 2020, 22:36:06) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 5.4.0-66-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.12.0 libnetcdf: 4.7.4 xarray: 0.17.0 pandas: 1.1.5 numpy: 1.19.5 scipy: None netCDF4: 1.5.6 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.4.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2021.02.0 distributed: None matplotlib: None cartopy: None seaborn: None numbagg: None pint: None setuptools: 49.6.0 pip: 20.2.2 conda: None pytest: None IPython: 7.21.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4973/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue