apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.67k stars 3.56k forks source link

[Python] Add `__getattr__` to `pyarrow.compute` for typing #43285

Open randolf-scholz opened 4 months ago

randolf-scholz commented 4 months ago

Describe the enhancement requested

When type-checking with pyright, the module pyarrow.compute raises tons of errors of the form

error: "sum" is not a known attribute of module "pyarrow.compute" (reportAttributeAccessIssue)

One can use the useLibraryCodeForTypes=false option to suppress these, but it's not configurable on a per-module basis.

The problem is that these are dynamically generated via https://github.com/apache/arrow/blob/c3aad6ad53a3a8b5106acd49c979f902b1b7aab9/python/pyarrow/compute.py#L336

A workaround until stubs are available would be to add a module-level __getattr__ function:

if TYPE_CHECKING:
    def __getattr__(self, name: str, /) -> Any: ...

See: https://github.com/microsoft/pyright/issues/3909#issuecomment-1236365288

Component(s)

Python

zen-xu commented 2 months ago

please install pyarrow-stubs

pip install 'pyarrow-stubs>=17.2'
image