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 1632718954,I_kwDOAMm_X85hUVBq,7652,Saving and loading an array of strings changes datatype to object,6897215,closed,0,,,13,2023-03-20T19:15:03Z,2023-11-17T15:26:01Z,2023-11-17T15:26:01Z,NONE,,,,"### What is your issue? See the code below ```python import xarray as xr # Make an xarray with an array of strings da = xr.DataArray( data=[[""a"", ""b""], [""c"", ""d""]], dims=[""x"", ""y""], coords={""x"": [0, 1], ""y"": [0, 1]}, ) da.to_netcdf(""test.nc"", mode='w') # Load the xarray back in da_loaded = xr.load_dataarray(""test.nc"") assert da.dtype == da_loaded.dtype, ""Dtypes don't match"" ``` Now `da_loaded.dtype` is `dtype('O')`. Same happens with `engine=""h5netcdf""`. ``` import xarray xarray.show_versions() ``` ``` INSTALLED VERSIONS ------------------ commit: None python: 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:26:40) [Clang 14.0.6 ] python-bits: 64 OS: Darwin OS-release: 22.3.0 machine: arm64 processor: arm byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: None xarray: 2023.2.0 pandas: 1.5.3 numpy: 1.24.2 scipy: 1.10.0 netCDF4: None pydap: None h5netcdf: 1.1.0 h5py: 3.8.0 Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.7.0 cartopy: None seaborn: 0.12.2 numbagg: None fsspec: 2023.1.0 cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 67.3.2 pip: 23.0 conda: None pytest: 7.2.1 mypy: 1.0.1 IPython: 8.10.0 sphinx: 5.3.0 ```","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/7652/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 207283854,MDU6SXNzdWUyMDcyODM4NTQ=,1265,variable length of a dimension in DataArray,6897215,closed,0,,,7,2017-02-13T17:22:38Z,2020-12-26T15:05:59Z,2020-12-26T15:05:59Z,NONE,,,,"I am having the following issue, say I have this code where I find eigenvalues of some system composed of the variables `A`, `B`, `C`, and `D`. In my example the number of eigenvalues (`num_eigs`) is constant. However, in general this number is not constant. Is there a way in `xarray` to handle this issue? ``` import numpy as np import xarray as xr A = np.linspace(0, 40, 10) B = np.linspace(0, 1, 20) C = np.linspace(0, 1, 30) D = np.linspace(-3, 3, 40) num_eigs = 4 # pretend like this is taking the eigenvalues of a matrix composed with A, B, C, and D res = np.random.rand(len(A), len(B), len(C), len(D), num_eigs) # now I need to set the last dimension to `range(res.shape[-1]))` da = xr.DataArray(res, coords= [('A', A), ('B', B), ('C', C), ('D', D), ('eig', range(res.shape[-1]))]) ``` For those that ask why I would need this: I do numerics in quantum mechanics and create quantum systems with certain parameters. Some of these parameters could be the system size. This would result in different Hamiltonians (a matrix describing the system) and therefore in a different number of eigenvalues.","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/1265/reactions"", ""total_count"": 2, ""+1"": 2, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue