Skip to content

[Python] type checkers broken for pyarrow.compute and other sub-modules since PyArrow 24.0+ #49831

Description

@jameslamb

Describe the bug, including details regarding any error messages, version, and platform.

Consider the following snippet:

docker run \
  --rm \
  -it python:3.13 \
  bash

pip install 'pyarrow>=24.0' 'mypy'

cat > test.py <<EOF
import pyarrow as pa
import pyarrow.compute as pa_compute

def all_ones(arr) -> bool:
    return pa_compute.all(pa_compute.equal(arr, 1))

if __name__ == "__main__":
    X = pa.array([1, 1, 1])
    print(f"all ones?: {all_ones(X)}")
EOF

This is totally plausible pyarrow code and works as expected.

$ python ./test.py
all ones?: True

But mypy complains about it referencing things that don't exist in pyarrow

$ mypy --version
mypy 1.20.2 (compiled: yes)

$ mypy ./test.py
test.py:5: error: Module has no attribute "all"  [attr-defined]
test.py:5: error: Module has no attribute "equal"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

Notes

Similar errors are not surfaced by type checkers like mypy on pyarrow<24, so I strongly suspect this is related to something new in the 24.0 release. Possibly the introduction of type-checking infrastructure (a py.typed file and .pyi stubs), around #48618

Maybe the .pyi stub file(s) are incomplete? At https://mypy.readthedocs.io/en/stable/stubs.html#creating-a-stub, I see:

If a directory contains both a .py and a .pyi file for the same module, the .pyi file takes precedence.

Or maybe mypy does not handle well situations where things are added to globals at import time like this?

_make_global_functions()

Thanks for your time and consideration.

Component(s)

Python

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions