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

pandas-stubs resulting in mypy to fail at initialization #1019

Closed
jindongyang94 opened this issue Oct 23, 2024 · 6 comments
Closed

pandas-stubs resulting in mypy to fail at initialization #1019

jindongyang94 opened this issue Oct 23, 2024 · 6 comments

Comments

@jindongyang94
Copy link

Describe the bug
mypy is unable to run with the following error when pandas-stubs is installed. The error is as following:
Traceback (most recent call last):
File "/code/.venv/bin/mypy", line 8, in
sys.exit(console_entry())
^^^^^^^^^^^^^^^
File "/code/.venv/lib/python3.11/site-packages/mypy/main.py", line 15, in console_entry
main()
File "mypy/main.py", line 102, in main
File "mypy/main.py", line 186, in run_build
File "mypy/build.py", line 194, in build
File "mypy/build.py", line 269, in _build
File "mypy/build.py", line 2935, in dispatch
File "mypy/build.py", line 3333, in process_graph
File "mypy/build.py", line 3460, in process_stale_scc
File "mypy/build.py", line 2497, in write_cache
File "mypy/build.py", line 1559, in write_cache
File "mypy/nodes.py", line 390, in serialize
File "mypy/nodes.py", line 4010, in serialize
File "mypy/nodes.py", line 3947, in serialize
File "mypy/nodes.py", line 3371, in serialize
File "mypy/types.py", line 682, in serialize
File "mypy/types.py", line 2475, in serialize
File "mypy/types.py", line 1498, in serialize
File "mypy/types.py", line 682, in serialize
File "mypy/types.py", line 3160, in serialize
AssertionError: Internal error: unresolved placeholder type None

When pandas-stubs is uninstalled, the following result will be seen:
Success: no issues found in 1 source file

When a different command is ran with pandas-stubs installed, the following result will be seen:
Success: no issues found in 1 source file

To Reproduce

  1. pip install pandas-stubs & mypy in a python3.11 virtual environment
  2. run command mypy -c 'import pandas as pd' - this will fail
  3. run command mypy -c 'import os' - this will pass

Please complete the following information:

  • OS: Linux (Windows WSL2)
  • OS Version - Ubuntu 22.04.2 LTS
  • python version 3.11.10
  • version of type checker - mypy: 1.13.0 & mypy-extensions: 1.0.0
  • version of installed pandas-stubs - pandas-stubs-2.2.3.241009

Additional context
pre-commit is working but likely it is due to not having pandas-stubs installed.
Likely not a pandas-stubs issue, but just want to point out that it is also frustrating that the above error did not proper tracebacks to know that pandas-stubs was the library that caused it - I had trial and error with many individual scripts to reproduce it efficiently.

@jindongyang94 jindongyang94 changed the title pandas-stubs reuslting in mypy to fail at initialization pandas-stubs resulting in mypy to fail at initialization Oct 23, 2024
@hauntsaninja
Copy link
Contributor

I wasn't able to repro:

λ uv pip freeze
Using Python 3.11.6 environment at /Users/shantanujain/.virtualenvs/tmpvenv-qscr
mypy==1.13.0
mypy-extensions==1.0.0
numpy==2.1.2
pandas-stubs==2.2.3.241009
pip==24.2
setuptools==75.1.0
types-pytz==2024.2.0.20241003
typing-extensions==4.12.2
wheel==0.44.0

λ mypy -c 'import pandas as pd'                      
Success: no issues found in 1 source file
mypy -c 'import pandas as pd'  2.10s user 0.29s system 17% cpu 13.914 total

Do you have a mypy config file or something?

@kristian4cast
Copy link

Do you have a mypy config file or something?

For me, this issue occurs when follow imports is set to "error" (or "skip"), i.e.
mypy -c 'import pandas as pd' --follow-imports "error"
reproduces the error for me.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 5, 2024

For me, this issue occurs when follow imports is set to "error" (or "skip"), i.e. mypy -c 'import pandas as pd' --follow-imports "error" reproduces the error for me.

@hauntsaninja I was able to reproduce in a clean environment, python 3.12, mypy 1.13.0 with latest pandas-stubs

mypy -c "import pandas as pd" --follow-imports "error"
Traceback (most recent call last):
  File "C:\Condadirs\envs\pandasstubstest\Scripts\mypy-script.py", line 10, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "C:\Condadirs\envs\pandasstubstest\Lib\site-packages\mypy\__main__.py", line 15, in console_entry
    main()
  File "mypy\main.py", line 102, in main
  File "mypy\main.py", line 186, in run_build
  File "mypy\build.py", line 194, in build
  File "mypy\build.py", line 269, in _build
  File "mypy\build.py", line 2935, in dispatch
  File "mypy\build.py", line 3333, in process_graph
  File "mypy\build.py", line 3460, in process_stale_scc
  File "mypy\build.py", line 2497, in write_cache
  File "mypy\build.py", line 1559, in write_cache
  File "mypy\nodes.py", line 390, in serialize
  File "mypy\nodes.py", line 4010, in serialize
  File "mypy\nodes.py", line 3947, in serialize
  File "mypy\nodes.py", line 3371, in serialize
  File "mypy\types.py", line 682, in serialize
  File "mypy\types.py", line 2475, in serialize
  File "mypy\types.py", line 1498, in serialize
  File "mypy\types.py", line 682, in serialize
  File "mypy\types.py", line 3160, in serialize
AssertionError: Internal error: unresolved placeholder type None

@hauntsaninja
Copy link
Contributor

Sounds like python/mypy#17396

(Obligatory note: while this is certainly a bad bug, in my experience most people using a non-default value of --follow-imports are better served by not doing so)

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 5, 2024

Closing this issue here as it is a mypy issue, not a pandas-stubs issue.

@Dr-Irv Dr-Irv closed this as completed Nov 5, 2024
@jindongyang94
Copy link
Author

Thanks everyone! It is indeed a --follow-imports issue due to numpy2.0.0 (managed to reproduce the same error on my end).

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

No branches or pull requests

4 participants