Skip to content

[Python] PyArrow 24.0+: 'mypy' reports 'compute.all' and 'compute.equal' as missing #49831

@jameslamb

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions