Closed PetitLepton closed 1 year ago
hi @PetitLepton I'm unable to reproduce the error. I'm installing the same versions of mypy
, pandas
, and pandas-stubs
on my virtual env and I get:
❯ mypy test.py
Success: no issues found in 1 source file
Can you provide more details on what OS and Python version you're on?
hi @PetitLepton I'm unable to reproduce the error. I'm installing the same versions of
mypy
,pandas
, andpandas-stubs
on my virtual env and I get:❯ mypy test.py Success: no issues found in 1 source file
Can you provide more details on what OS and Python version you're on?
Hi @cosmicBboy , thanks for the quick update. I am on Ubuntu 22.10. I used conda/mamba to create the virtual environment as shown above for python 3.10.9. Then pip for the rest.
You may have to debug this on your side. It looks like the offending line is https://github.com/unionai-oss/pandera/blob/main/pandera/api/pandas/model.py#L563
Can you try noodling around with this to see what happens? Some ideas:
SchemaModel = DataFrameModel
: I think this caused some other issues when I was writing this.--show-traceback
mypy flag?Here is the report
mypy test.py --show-traceback
/home/flavien/.conda/envs/test-mypy/lib/python3.10/site-packages/pandera/api/pandas/model.py:563: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.1.1
Traceback (most recent call last):
File "mypy/semanal.py", line 6261, in accept
File "mypy/nodes.py", line 1123, in accept
File "mypy/semanal.py", line 1561, in visit_class_def
File "mypy/semanal.py", line 1641, in analyze_class
File "mypy/semanal.py", line 1668, in analyze_class_body_common
File "mypy/semanal.py", line 1751, in apply_class_plugin_hooks
File "/home/flavien/.conda/envs/test-mypy/lib/python3.10/site-packages/pandera/mypy.py", line 93, in _pandera_model_class_maker_callback
transformer.transform()
File "/home/flavien/.conda/envs/test-mypy/lib/python3.10/site-packages/pandera/mypy.py", line 125, in transform
self.erase_field_type_arg()
File "/home/flavien/.conda/envs/test-mypy/lib/python3.10/site-packages/pandera/mypy.py", line 140, in erase_field_type_arg
type_ = def_.type
AttributeError: 'ExpressionStmt' object has no attribute 'type'
/home/flavien/.conda/envs/test-mypy/lib/python3.10/site-packages/pandera/api/pandas/model.py:563: : note: use --pdb to drop into pdb
The SchemaModel = DataFrameModel
removes the error.
To be "sure," I performed the same set operations in a Docker container using python:3.10-slim-buster
and the result is the same.
are you using any other mypy configuration settings?
Not that I know of. And that should not come into play when using the Docker container if I am not mistaken.
I noticed you're using pandas-stubs==1.4.3.220807
. Any particular reason you're using this version? can you try pandas-stubs==1.5.2.221213
It doesn't seem to change the result.
Here is the Dockerfile that reproduces the issue on my machine.
FROM python:3.10-slim-buster
RUN pip install mypy pandera[mypy]==0.14.3
WORKDIR /tmp
RUN echo '[tool.mypy]\nplugins = ["pandera.mypy"]' > pyproject.toml
RUN echo 'import pandera\nimport pandas' > test.py
CMD ["mypy", "--show-traceback", "/tmp/test.py"]
This
docker build -t test-mypy:0.1 . && docker run -i test-mypy:0.1
gives me the issue.
https://github.com/unionai-oss/pandera/pull/1123 should address this issue.
I was able to repro this with your dockerfile, but it's concerning that I couldn't repro on my mac 🤷♂️. I'd prefer not to be flying in the dark on this, but then again mypy support for pandera is still experimental and it's a bumpy road if you want to use pandas-stubs
and pandera
mypy type-linting :)
Can you confirm that this works for you?
FROM python:3.10-slim-buster
RUN apt-get update && apt-get install -y git
RUN pip install git+https://github.com/unionai-oss/pandera@bugfix/1121 mypy pandas-stubs==1.5.2.221213
WORKDIR /tmp
RUN echo '[tool.mypy]\nplugins = ["pandera.mypy"]' > pyproject.toml
RUN echo 'import pandera\nimport pandas' > test.py
CMD ["mypy", "--show-traceback", "/tmp/test.py"]
@cosmicBboy I am away from laptop right now. Let me confirm that tomorrow morning, Paris time. In the meantime, thanks for the effort and the library.
Describe the bug It seems that versions 0.14.x break the compatibility with
mypy
.Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
pyproject.toml
test.py
leads to
but
is OK
Expected behavior
Consistent behaviour with version
0.13.4
.Desktop (please complete the following information):