aliyun / alibabacloud-odps-maxframe-client

Apache License 2.0
3 stars 1 forks source link

dataframe with multindex div error: Length mismatch: Expected axis has 3 elements, new values have 2 elements #28

Open snowljs opened 1 week ago

snowljs commented 1 week ago

error message

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/maxframe/odpsio/arrow.py:58](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/maxframe/odpsio/arrow.py#line=57), in arrow_to_pandas(arrow_table, table_meta)
     56 df = arrow_table.to_pandas()
     57 if table_meta.type in (OutputType.dataframe, OutputType.series):
---> 58     return _rebuild_dataframe(df, table_meta)
     59 elif table_meta.type == OutputType.index:
     60     return _rebuild_index(df, table_meta)

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/maxframe/odpsio/arrow.py:40](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/maxframe/odpsio/arrow.py#line=39), in _rebuild_dataframe(df, table_meta)
     36 else:
     37     cols = pd.MultiIndex.from_tuples(table_meta.pd_column_names).set_names(
     38         table_meta.pd_column_level_names
     39     )
---> 40 indexed.columns = cols
     41 if table_meta.type == OutputType.series:
     42     return indexed.iloc[:, 0]

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/generic.py:5915](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/generic.py#line=5914), in NDFrame.__setattr__(self, name, value)
   5913 try:
   5914     object.__getattribute__(self, name)
-> 5915     return object.__setattr__(self, name, value)
   5916 except AttributeError:
   5917     pass

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/_libs/properties.pyx:69](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/_libs/properties.pyx#line=68), in pandas._libs.properties.AxisProperty.__set__()

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/generic.py:823](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/generic.py#line=822), in NDFrame._set_axis(self, axis, labels)
    821 def _set_axis(self, axis: int, labels: AnyArrayLike | list) -> None:
    822     labels = ensure_index(labels)
--> 823     self._mgr.set_axis(axis, labels)
    824     self._clear_item_cache()

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/internals/managers.py:230](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/internals/managers.py#line=229), in BaseBlockManager.set_axis(self, axis, new_labels)
    228 def set_axis(self, axis: int, new_labels: Index) -> None:
    229     # Caller is responsible for ensuring we have an Index object.
--> 230     self._validate_set_axis(axis, new_labels)
    231     self.axes[axis] = new_labels

File [~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/internals/base.py:70](http://localhost:8888/lab/tree/~/anaconda3/envs/py311/lib/python3.11/site-packages/pandas/core/internals/base.py#line=69), in DataManager._validate_set_axis(self, axis, new_labels)
     67     pass
     69 elif new_len != old_len:
---> 70     raise ValueError(
     71         f"Length mismatch: Expected axis has {old_len} elements, new "
     72         f"values have {new_len} elements"
     73     )

ValueError: Length mismatch: Expected axis has 3 elements, new values have 2 elements

maxframe code

df = md.DataFrame({'angles': [0, 3, 4],
                   'degrees': [360, 180, 360]},
                  index=['circle', 'triangle', 'rectangle'])
df_multindex = md.DataFrame({'angles': [0, 3, 4, 4, 5, 6],
                             'degrees': [360, 180, 360, 360, 540, 720]},
                            index=[['A', 'A', 'A', 'B', 'B', 'B'],
                                   ['circle', 'triangle', 'rectangle',
                                    'square', 'pentagon', 'hexagon']])
df.div(df_multindex, level=1, fill_value=0).execute()