home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1433104955

This data as json

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/7076#issuecomment-1433104955 https://api.github.com/repos/pydata/xarray/issues/7076 1433104955 IC_kwDOAMm_X85Va3I7 18679148 2023-02-16T13:41:12Z 2023-02-16T13:41:12Z NONE

Hi @benbovy, my code works for 2 dimensions, but it doesn't with 1D. I think the error comes from .set_index(z=['across']) which delivers a "PandasIndex(Int64Index(" and not the expected "PandasIndex(MultiIndex(" for unstack.

I created a Pandas-MultiIndex "MultiIndex([((0,), (1,))], names=['z', 'across'])" (see code just below), but it is not exactly the same one as the one created by .stack() "PandasIndex(MultiIndex([(0,),(1,)], name='z'))" and I didn't find out how to pass the 'index' to xarray. python import pandas as pd tuples = [(0,),(1,)], index = pd.MultiIndex.from_tuples(tuples, names=["z","across"]) index

My modified minimal example is as below: python import xarray as xr ds = xr.Dataset( data_vars=dict( mydata = ( ['across', 'along'], [[0,1],[2,3]]) ), coords=dict( # <- changed across=[0,1], # <- changed along=[0,1], # <- changed ), # <- changed ) stacked = ds.isel(along=0).stack(z=["across"]) # <- changed newlist = [None] * stacked.z.size for ii, zindex in enumerate(stacked.z.data): newlist[ii] = stacked.mydata.sel(z=zindex) newds = xr.concat(newlist, dim='z') newds = newds.set_index(z=['across']) # <- changed newds.unstack(dim='z') # Fail with ValueError: cannot unstack dimensions that do not have exactly one multi-index: ('z',)

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  1384465119
Powered by Datasette · Queries took 0.8ms · About: xarray-datasette