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 361237908,MDU6SXNzdWUzNjEyMzc5MDg=,2419,Document ways to reshape a DataArray,9844249,open,0,,,5,2018-09-18T10:27:36Z,2022-04-09T02:21:15Z,,NONE,,,,"#### Code Sample, a copy-pastable example if possible A ""Minimal, Complete and Verifiable Example"" will make it much easier for maintainers to help you: http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports ```python # Your code here def xr_reshape(A, dim, newdims, coords): """""" Reshape DataArray A to convert its dimension dim into sub-dimensions given by newdims and the corresponding coords. Example: Ar = xr_reshape(A, 'time', ['year', 'month'], [(2017, 2018), np.arange(12)]) """""" # Create a pandas MultiIndex from these labels ind = pd.MultiIndex.from_product(coords, names=newdims) # Replace the time index in the DataArray by this new index, A1 = A.copy() A1.coords[dim] = ind # Convert multiindex to individual dims using DataArray.unstack(). # This changes dimension order! The new dimensions are at the end. A1 = A1.unstack(dim) # Permute to restore dimensions i = A.dims.index(dim) dims = list(A1.dims) for d in newdims[::-1]: dims.insert(i, d) for d in newdims: _ = dims.pop(-1) return A1.transpose(*dims) ``` #### Problem description [this should explain **why** the current behavior is a problem and why the expected output is a better solution.] It would be great to have the above function as a DataArray's method. #### Expected Output A reshaped DataArray. In the example in the function comment it would correspond to an array like In[1] Ar.dims Out[1]: ('year', 'month', 'lat', 'lon') #### Output of ``xr.show_versions()``
# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.3.final.0 python-bits: 64 OS: Linux OS-release: 3.10.0-693.5.2.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: fr_FR.UTF-8 LOCALE: fr_FR.UTF-8 xarray: 0.10.4 pandas: 0.23.0 numpy: 1.13.3 scipy: 0.19.1 netCDF4: 1.3.1 h5netcdf: None h5py: 2.7.0 Nio: None zarr: None bottleneck: 1.2.1 cyordereddict: None dask: 0.15.3 distributed: 1.19.1 matplotlib: 2.1.0 cartopy: 0.16.0 seaborn: 0.8.1 setuptools: 36.5.0.post20170921 pip: 18.0 conda: 4.4.7 pytest: 3.2.1 IPython: 6.1.0 sphinx: 1.6.3
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2419/reactions"", ""total_count"": 2, ""+1"": 2, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue 221845134,MDU6SXNzdWUyMjE4NDUxMzQ=,1373,Dataset.combine_first() coordinates attribute,9844249,closed,0,,,2,2017-04-14T16:46:02Z,2019-04-14T23:22:23Z,2019-04-14T23:22:23Z,NONE,,,,"Hi guys! Thanks for the great job you are doing! Here is a possible bug in the `Dataset.combine_first()` method (I'm using xarray 0.9.2 with Python 3.5.2). The Dataset/DataArray coordinates are correctly treated if specified without commas, e.g. (as seen with ncdump): ``MyVar:coordinates = ""alt lat lon"" ; ``. In this case _lon, lat_, and _alt_ are recognized as the Dataset's (and its DataArrays') `.coords`. However, the `Dataset.combine_first() `method only treats coordinates correctly if specified with commas, i.e., `MyVar:coordinates = ""alt, lat, lon""`. ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/1373/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue