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/4228#issuecomment-715987107,https://api.github.com/repos/pydata/xarray/issues/4228,715987107,MDEyOklzc3VlQ29tbWVudDcxNTk4NzEwNw==,2448579,2020-10-24T16:47:34Z,2020-10-24T16:47:34Z,MEMBER,"> f that's good enough to open a pull request and ask for a review. please go ahead and open a PR. Thanks. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,657466413 https://github.com/pydata/xarray/issues/4228#issuecomment-715958475,https://api.github.com/repos/pydata/xarray/issues/4228,715958475,MDEyOklzc3VlQ29tbWVudDcxNTk1ODQ3NQ==,15890747,2020-10-24T16:04:36Z,2020-10-24T16:04:36Z,CONTRIBUTOR,"Hi, I tried to work on this issue. I made the changes on the `fix_#4228` branch of my fork (all in [this commit](https://github.com/PGijsbers/xarray/commit/50d1ac9b82ff43c1a11f19ed554acd23219bf1c8)). Unfortunately I can't currently reproduce the full test environment. I am running `python` through the standard release and not `anaconda/miniconda`, and I am hesitant to install it alongside my current setup because that has caused some issues in the past. Simply installing `pytest` in my environment did allow me to run some tests (4031 passed, 4237 skipped, 66 xfailed, 15 xpassed, 41 warnings). Most notably the edited test ran successfully (i.e. pass on fresh pull, fail after I updated the test, pass again after I updated code). Please let me know if that's good enough to open a pull request and ask for a review.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,657466413 https://github.com/pydata/xarray/issues/4228#issuecomment-658932130,https://api.github.com/repos/pydata/xarray/issues/4228,658932130,MDEyOklzc3VlQ29tbWVudDY1ODkzMjEzMA==,2448579,2020-07-15T18:32:36Z,2020-07-15T18:32:36Z,MEMBER,"You could do it with ""advanced indexing"" by providing a dataarray to the `.sel` or `.isel` methods: https://xarray.pydata.org/en/stable/indexing.html#more-advanced-indexing ``` python da = xr.DataArray([[1, 2, 3], [4,5,6]], dims=[""coord1"", ""coord2""], coords={""coord2"": [10, 20, 30], ""coord1"": [1,2]}) i1 = xr.DataArray([1, 0], dims=[""z""], coords={""z"": [""label1"", ""label2""]}) i2 = xr.DataArray([2, 1], dims=[""z""], coords={""z"": [""label1"", ""label2""]}) da.isel(coord1=i1, coord2=i2, drop=True).to_dataframe(name=""asd"") ``` ``` asd z label1 6 label2 2 ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,657466413 https://github.com/pydata/xarray/issues/4228#issuecomment-658912550,https://api.github.com/repos/pydata/xarray/issues/4228,658912550,MDEyOklzc3VlQ29tbWVudDY1ODkxMjU1MA==,10563614,2020-07-15T17:54:57Z,2020-07-15T18:29:20Z,CONTRIBUTOR,"thanks for the very clear response. The behaviro make sense. In fact, I should have explained what I'm trying to achieve, as this is kind of ""take"". I've a dict like this: ``` python {'label1' : dict(coord1=1, coord2=4), 'label2' : dict(coord1=5, coord2=6), 'label3' : dict(coord1=4, coord2=2), } ``` and I want to build an xarray (and then a dataframe) with coord1 and coord2 replaced by a new dims with values 'label1', 'label2', 'label3'. I've done that by iterating over the dict, selecting with sel using the dict values, convert to dataframe and then concat the dataframes. pd.concat([x.sel(**d[k]).to_dataframe() or k in d] A better option would be to do this ""sel"" or ""take"" with xarray only. Do you have an idea how to do it with existing xarray methods? ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,657466413 https://github.com/pydata/xarray/issues/4228#issuecomment-658884817,https://api.github.com/repos/pydata/xarray/issues/4228,658884817,MDEyOklzc3VlQ29tbWVudDY1ODg4NDgxNw==,2448579,2020-07-15T17:02:14Z,2020-07-15T17:02:14Z,MEMBER,"You need ``` xr.DataArray([1], coords=[('onecoord', [2])]).sel(onecoord=[2]).to_dataframe(name='name') ``` The difference is using `onecoord=2` gives a scalar ``` >>> xr.DataArray([1], coords=[('onecoord', [2])]).sel(onecoord=2) array(1) Coordinates: onecoord int64 2 ``` while using `onecoord=[2]` gives a 1 element vector ``` >>> xr.DataArray([1], coords=[('onecoord', [2])]).sel(onecoord=[2]) array([1]) Coordinates: * onecoord (onecoord) int64 2 ``` And `to_dataframe` cannot handle scalars. I am not sure that there is a sensible way to convert a scalar DataArray to a DataFrame but we should throw a more informative error in any case. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,657466413