Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

piping to verbs is not passing the dataframe argument #149

Closed
ftobin opened this issue Oct 8, 2022 · 15 comments · Fixed by pwwang/pipda#39
Closed

piping to verbs is not passing the dataframe argument #149

ftobin opened this issue Oct 8, 2022 · 15 comments · Fixed by pwwang/pipda#39

Comments

@ftobin
Copy link

ftobin commented Oct 8, 2022

Piping into verbs like mutate seems to be broken in 0.9.0. Passing in the dataframe directly works, but still generates a warning.

>>> import datar.all
>>> import datar.datasets
>>> datar.datasets.mtcars >> datar.all.mutate(x = 3)
/home/bizdev/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pipda/utils.py:68: VerbCallingCheckWarning: Failed to detect AST node calling `mutate`, assuming a normal call.
  warnings.warn(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bizdev/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pipda/verb.py", line 216, in __call__
    raise TypeError(f"{self.__name__}() missing at least one argument.")
TypeError: mutate() missing at least one argument.
>>> datar.__version__
'0.9.0'
>>> import pipda
>>> pipda.__version__
'0.7.6'

>>> datar.all.mutate(datar.datasets.mtcars, x = 3)
/home/bizdev/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pipda/utils.py:68: VerbCallingCheckWarning: Failed to detect AST node calling `mutate`, assuming a normal call.
  warnings.warn(
                          mpg     cyl      disp      hp      drat        wt      qsec      vs      am    gear    carb       x
                    <float64> <int64> <float64> <int64> <float64> <float64> <float64> <int64> <int64> <int64> <int64> <int64>
Mazda RX4                21.0       6     160.0     110      3.90     2.620     16.46       0       1       4       4       3
Mazda RX4 Wag            21.0       6     160.0     110      3.90     2.875     17.02       0       1       4       4       3

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

Are you running in plain python REPL, instead of ipython/bpython?

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

That was a plain repl.

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

It fails in a jupyter notebook too.

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

Downgrading to 0.8.6 allows it to succeed in both environments.

Correction -- downgrading allows it to work in Jupyter. I understand it doesn't work in the plain repl.

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

What does this print with 0.9.0 in your jupyter notebook?

from datar import get_versions

get_versions()

Also attach your jupyter version:

$ jupyter --version 

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

           [GCC 10.2.0]
datar    : 0.9.0
numpy    : 1.21.6
pipda    : 0.7.6
executing: 1.1.0
pandas   : 1.3.5

Selected Jupyter core packages...
IPython          : 7.34.0
ipykernel        : 6.15.1
ipywidgets       : not installed
jupyter_client   : 7.3.4
jupyter_core     : 4.11.1
jupyter_server   : 1.18.1
jupyterlab       : 3.4.5
nbclient         : 0.6.7
nbconvert        : 7.0.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : not installed
traitlets        : 5.3.0

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

And also your code that fails?

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

import datar.all
import datar.datasets

datar.datasets.mtcars >> datar.all.mutate(x=3)

/home/bizdev/.pyenv/versions/3.7.13/lib/python3.7/site-packages/pipda/utils.py:71: VerbCallingCheckWarning: Failed to detect AST node calling `mutate`, assuming a normal call.
  VerbCallingCheckWarning,

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_29360/1589615853.py in <module>
      2 import datar.datasets
      3 
----> 4 datar.datasets.mtcars >> datar.all.mutate(x=3)

~/.pyenv/versions/3.7.13/lib/python3.7/site-packages/pipda/verb.py in __call__(self, *args, **kwargs)
    214 
    215         if len(args) == 0:
--> 216             raise TypeError(f"{self.__name__}() missing at least one argument.")
    217 
    218         data, *args = args

TypeError: mutate() missing at least one argument.

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

It works with my environment. Looks like the major difference is the IPython version. Mind upgrading it and see if it works?

python   : 3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:24:11) 
           [GCC 9.4.0]
datar    : 0.9.0
numpy    : 1.23.2
pipda    : 0.7.6
executing: 1.0.0
pandas   : 1.4.3
Selected Jupyter core packages...
IPython          : 8.3.0
ipykernel        : 6.13.0
ipywidgets       : 7.7.0
jupyter_client   : 7.3.1
jupyter_core     : 4.11.1
jupyter_server   : 1.17.0
jupyterlab       : 3.4.2
nbclient         : 0.6.3
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.11
qtconsole        : 5.3.0
traitlets        : 5.3.0

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

Unfortunately the more recent ipython requires Python 3.8, and I'm stuck on 3.8 there for now.
I'll note that datar 0.8.6 works fine in this respect in Jupyter.

But I do have an alternate, up-to-date environment where this still fails:

python   : 3.9.13 (main, Aug 24 2022, 20:14:16) 
           [GCC 10.2.0]
datar    : 0.9.0
numpy    : 1.23.2
pipda    : 0.7.6
executing: 1.1.0
pandas   : 1.4.3

IPython          : 8.5.0
ipykernel        : 6.15.1
ipywidgets       : not installed
jupyter_client   : 7.3.4
jupyter_core     : 4.11.1
jupyter_server   : 1.18.1
jupyterlab       : 3.4.5
nbclient         : 0.6.7
nbconvert        : 7.0.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : not installed
traitlets        : 5.3.0

In [1]: import datar.all

In [2]: import datar.datasets

In [3]: datar.datasets.mtcars >> datar.all.mutate(x=3)
/home/bizdev/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pipda/utils.py:68: VerbCallingCheckWarning: Failed to detect AST node calling `mutate`, assuming a normal call.
  warnings.warn(
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [3], line 1
----> 1 datar.datasets.mtcars >> datar.all.mutate(x=3)

File ~/.pyenv/versions/3.9.13/lib/python3.9/site-packages/pipda/verb.py:216, in Verb.__call__(self, *args, **kwargs)
    213     return VerbCall(self, *args, **kwargs)
    215 if len(args) == 0:
--> 216     raise TypeError(f"{self.__name__}() missing at least one argument.")
    218 data, *args = args
    219 if has_expr(data):

TypeError: mutate() missing at least one argument.

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

How about switching executing to 1.0.0

$ pip install executing==1.0.0

@ftobin
Copy link
Author

ftobin commented Oct 8, 2022

That works!

@pwwang
Copy link
Owner

pwwang commented Oct 8, 2022

Great!
I will submit an issue to executing.

pwwang added a commit to pwwang/pipda that referenced this issue Oct 8, 2022
@pwwang pwwang mentioned this issue Oct 8, 2022
pwwang added a commit to pwwang/pipda that referenced this issue Oct 8, 2022
* 🐛 Patch classes if they have piping operator method

* ✨ Auto-register numpy ufuncs

* Fix linting

* pump executing to 1.1.1 to fix pwwang/datar#149

* 0.8.0
@pwwang
Copy link
Owner

pwwang commented Oct 13, 2022

Fixed at v0.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants