xorbitsai / xorbits

Scalable Python DS & ML, in an API compatible & lightning fast way.
https://xorbits.readthedocs.io
Apache License 2.0
1.11k stars 67 forks source link

BUG: Groupby object does not implement len() method #442

Open qianduoduo0904 opened 1 year ago

qianduoduo0904 commented 1 year ago

Describe the bug

Groupby object does not implement len() method.

To Reproduce

To help us to reproduce this bug, please provide information below:

  1. Your Python version
  2. The version of Xorbits you use
  3. Versions of crucial packages, such as numpy, scipy and pandas
  4. Full stack of the error.
  5. Minimized code to reproduce the error.
In [1]: import xorbits.pandas as pd

In [2]: df = pd.DataFrame({'a': ['a', 'b', 'a', 'c'], 'b': [0.1, 0.2, 0.3, 0.4], 'c': ['aa', 'bb', 'cc', 'aa']})

In [3]: grouped = df.groupby('b')

In [4]: len(grouped)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 len(grouped)

File ~/Workspace/xorbits/python/xorbits/core/data.py:267, in DataRef.__len__(self)
    263             raise TypeError(
    264                 f"object with shape {self.data._mars_entity.shape} has no len()"
    265             )
    266 else:
--> 267     raise TypeError(f"object of type '{self.data.data_type}' has no len()")

TypeError: object of type 'DataType.dataframe_groupby' has no len()

Expected behavior

__len__() implementd.

RayJi01 commented 1 year ago

take