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

Failed to detect AST nodes in Windows ipython for verb calls #170

Closed
1 of 3 tasks
GitHunter0 opened this issue Jan 17, 2023 · 21 comments
Closed
1 of 3 tasks

Failed to detect AST nodes in Windows ipython for verb calls #170

GitHunter0 opened this issue Jan 17, 2023 · 21 comments
Labels
3rd-party Issues due to 3rd-party packages/tools

Comments

@GitHunter0
Copy link
Collaborator

Feature Type

  • Adding new functionality to datar

  • Changing existing functionality in datar

  • Removing existing functionality in datar

Problem Description

The code below

    import datar.all as d
    import pandas as pd
    new_name = "y"
    pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name: 'x'})

generates the following warning message:

c:\Users\me\miniconda3\envs\cenv\lib\site-packages\pipda\utils.py:89: PipeableCallCheckWarning:
Failed to detect AST node calling `rename`, assuming a piping call.

Feature Description

Being able to suppress the warning message above.

Additional Context

No response

@GitHunter0 GitHunter0 added the enhancement New feature or request label Jan 17, 2023
@pwwang
Copy link
Owner

pwwang commented Jan 17, 2023

Could you also indicate the environment where you were running the code? i.e. python script, jupyter, python REPL, etc

@GitHunter0
Copy link
Collaborator Author

For sure @pwwang , I'm using in a .py file in VScode (via its Interactive Window, which uses jupyter kernel).

@pwwang
Copy link
Owner

pwwang commented Jan 17, 2023

I can run it with no problem:

image

here is the version info:

Version: 1.74.3 (system setup)
Commit: 97dec172d3256f8ca4bfb2143f3f76b503ca0534
Date: 2023-01-09T16:59:02.252Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.25276
Sandboxed: No
vscode-jupyter: v2022.11.1003412109

@GitHunter0
Copy link
Collaborator Author

The problem was indeed with VScode, I updated it to the last version and that warning message disappeared, thank you @pwwang .

@GitHunter0
Copy link
Collaborator Author

@pwwang , I checked that the issue was solved only for python 3.8 (after I updated datar and restarted VScode).
All conda environments I tested with python 3.9 or 3.10 that message appears, even directly in the command prompt (without VScode and ipython), it's very weird...

@GitHunter0
Copy link
Collaborator Author

Steps to reproduce the issue.
Go to Windows OS powershell and type:

conda create --name py3.9 python=3.9 
conda activate py3.9 
pip install datar[pandas] 
python

Then run:

    import datar.all as d
    import pandas as pd
    new_name = "y"
    pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name: 'x'})

It will display this message:

C:\Users\me\miniconda3\envs\py3.9\lib\site-packages\pipda\utils.py:89: PipeableCallCheckWarning: Failed to detect AST node calling `rename`, assuming a piping call.
  warnings.warn(

@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

This is expected.
There is some description here: https://pwwang.github.io/pipda/piping/#fallbacks-when-ast-node-detection-fails

Tracing executing node is not available in the raw python REPL.
How about ipython or bpython?

@GitHunter0
Copy link
Collaborator Author

I could not install bpython to test, but with ipython the same issue occurs and since VScode relies on ipython for its Interactive Window, it inherits the same behavior.

@GitHunter0
Copy link
Collaborator Author

GitHunter0 commented Jan 18, 2023

Maybe an option to temporarily silent that message would suffice as a workaround (in the context of a function, we could turn off in the beginning and turn on in the end).

@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

You can silence it by:

pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name: 'x'}, __ast_fallback="piping")

It's kinda wired that ipython shows the same issue.

Could you provide datar.get_versions() and also the version of your python?

@GitHunter0
Copy link
Collaborator Author

Awesome, __ast_fallback="piping" works.

Could you provide datar.get_versions() and also the version of your python?

For sure:

python      : 3.9.16 (main, Jan 11 2023, 16:16:36) [MSC v.1916 64 bit (AMD64)]
datar       : 0.11.1
simplug     : 0.2.2
executing   : 1.2.0
pipda       : 0.11.0
datar-numpy : 0.1.0
numpy       : 1.24.1
datar-pandas: 0.2.0
pandas      : 1.5.2

The python version installed on my Windows OS is 3.9.4.

@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

The python version installed on my Windows OS is 3.9.4.

Sorry, I meant ipython.

@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

pipda v0.11.1 was just released. With it, you can change the default fallback of a verb:

# importing ...
d.rename.ast_fallback  = "piping"
# So you don't need to pass "__ast_fallback" to every call
new_name1 = 'y'
new_name2 = 'z'
pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name1: 'x'})
pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name2: 'x'})

@GitHunter0
Copy link
Collaborator Author

pipda v0.11.1 was just released. With it, you can change the default fallback of a verb:

Very nice to know.

@GitHunter0
Copy link
Collaborator Author

Sorry, I meant ipython.

The ipython version is 8.8.0

@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

I don't see a critical difference between your environment and mine below:

image

Could you also take a similar snapshot?

@GitHunter0
Copy link
Collaborator Author

For sure:
image

@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

Looks like the only difference is the platform. I can reproduce the issue on Windows. The snapshot I took was on Linux (WSL).
I'll dig deeper to see if there is a fix.

@pwwang pwwang reopened this Jan 18, 2023
@pwwang pwwang changed the title [ENH] Suppress warning message when applying Non-Standard Evaluation Failed to detect AST nodes in Windows ipython for verb calls Jan 18, 2023
@pwwang pwwang added 3rd-party Issues due to 3rd-party packages/tools and removed enhancement New feature or request labels Jan 18, 2023
@pwwang
Copy link
Owner

pwwang commented Jan 18, 2023

Looks like it is due to a python bug on Windows. AST nodes cannot be detected when we are trying to deconstruct dicts as keyword-arguments.

new_name = 'y'
# Warns
pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name: 'x'})
# But this is Okay
pd.DataFrame(dict(x=[2])) >> d.rename(y='x')

Related:

alexmojaki/executing#27
samuelcolvin/python-devtools#93
samuelcolvin/python-devtools#93 (comment)
python/cpython#89271

@GitHunter0
Copy link
Collaborator Author

Great, at least now we know the root cause.

@pwwang
Copy link
Owner

pwwang commented Mar 6, 2023

Close it for now since this problem can not be solved in this repo.

A temporarily solution is to pass __ast_fallback to bypass the AST node detection:

pd.DataFrame(dict(x=[2])) >> d.rename(**{new_name: 'x'}, __ast_fallback="piping")

See more details here: https://pwwang.github.io/pipda/piping/#fallbacks-when-ast-node-detection-fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd-party Issues due to 3rd-party packages/tools
Projects
None yet
Development

No branches or pull requests

2 participants