pwwang / datar

A Grammar of Data Manipulation in python
https://pwwang.github.io/datar/
MIT License
267 stars 17 forks source link

[BUG] ContextError: Cannot evaluate `ReferenceAttr` object without a context #176

Closed sibananda-dream11 closed 1 year ago

sibananda-dream11 commented 1 year ago

datar version checks

Issue Description

Getting this error on trying to use any function(group_by,filter) from datar. ContextError: Cannot evaluate ReferenceAttr object without a context

Expected Behavior

Should have been running coreectly without any error.

Installed Versions

0.11.2
pwwang commented 1 year ago

Could you provide a copy of minimal runnable code, as well as the full version information?

sibananda-dream11 commented 1 year ago
Screenshot 2023-03-17 at 6 56 25 PM Screenshot 2023-03-17 at 6 56 44 PM
sibananda-dream11 commented 1 year ago
from datar.all import *
from datar import f
import pandas as pd
from sklearn import datasets as dt

ir = dt.load_iris(as_frame=True)
ir >> group_by(f.target)

I am getting error with this. Sorry it may be a basic error but i don't know how to make it run.

pwwang commented 1 year ago

The ir data you loaded is a dict:

>>> ir.keys()
# dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename', 'data_module'])

You should refer to the frame dataframe:

>>> from datar.all import *
>>> from datar import f
>>> import pandas as pd
>>> from sklearn import datasets as dt
>>>
>>> ir = dt.load_iris(as_frame=True)
>>> ir['frame'] >> group_by(f.target)

     sepal length (cm)  sepal width (cm)  petal length (cm)  petal width (cm)  target
             <float64>         <float64>          <float64>         <float64> <int64>
0                  5.1               3.5                1.4               0.2       0
1                  4.9               3.0                1.4               0.2       0
2                  4.7               3.2                1.3               0.2       0
3                  4.6               3.1                1.5               0.2       0
..                 ...               ...                ...               ...     ...
4                  5.0               3.6                1.4               0.2       0
145                6.7               3.0                5.2               2.3       2
146                6.3               2.5                5.0               1.9       2
147                6.5               3.0                5.2               2.0       2
148                6.2               3.4                5.4               2.3       2
149                5.9               3.0                5.1               1.8       2

[150 rows x 5 columns]
[TibbleGrouped: target (n=3)]
pwwang commented 1 year ago

By the way, you also need datar-pandas backend to be installed:

pip install -U datar[pandas]
# or
pip install -U datar-pandas