unionai-oss / pandera

A light-weight, flexible, and expressive statistical data testing library
https://www.union.ai/pandera
MIT License
3.14k stars 296 forks source link

Pyright does not recognize pandera.polars exports: reportPrivateImportUsage #1726

Open RmStorm opened 1 week ago

RmStorm commented 1 week ago

Describe the bug Pyright throws reportPrivateImportUsage errors on basically everything imported from pandera.polars.

Simply running pyright by hand on a minimal example like this will show the problem:

#!/usr/bin/python3
# privates.py
import pandera.polars as pa

class SomeSchema(pa.DataFrameModel):
    height: float
    horizontal_accuracy: float
    config_id: str = pa.Field(nullable=True)
➜ pyright privates.py 
/SNIP/privates.py
  /SNIP/privates.py:6:21 - error: "DataFrameModel" is not exported from module "pandera.polars" (reportPrivateImportUsage)
  /SNIP/privates.py:9:25 - error: "Field" is not exported from module "pandera.polars" (reportPrivateImportUsage)
2 errors, 0 warnings, 0 informations

Expected behavior

Running pyright (either by hand or indirectly as an LSP in an editor) should not give any errors. More importantly I don't expect little red squiggly lines on literally every import from pandera.polars.

Context

I'm currently on pandera version 0.20.1 and pyright version 1.1.368.

To me it looks like Pylance papers over these issues or swallows the error even though it's using pyright under the hood. The pyright folk are really pretty clear that this is as designed and it ought to be fixed in the libraries. See this issue in pyright for example.

If you agree this is an issue and should be fixed in pandera I can probably find the time to make a PR!

cosmicBboy commented 6 days ago

Hi @RmStorm, this is probably because the pandera.polars module doesn't define __all__... can you try adding it e.g. see here and see if the pyright error goes away?