|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | +import sys |
| 4 | +import tempfile |
| 5 | +import warnings |
| 6 | + |
| 7 | +from mypy import stubtest |
| 8 | + |
| 9 | +import pandas as pd |
| 10 | + |
| 11 | +# fail early if pandas is not installed |
| 12 | +if "dev" not in getattr(pd, "__version__", ""): |
| 13 | + # fail on the CI, soft fail during local development |
| 14 | + warnings.warn("You need to install the development version of pandas") |
| 15 | + if pd.compat.is_ci_environment(): |
| 16 | + sys.exit(1) |
| 17 | + else: |
| 18 | + sys.exit(0) |
| 19 | + |
| 20 | + |
| 21 | +_ALLOWLIST = [ # should be empty |
| 22 | + # TODO (child classes implement these methods) |
| 23 | + "pandas._libs.hashtable.HashTable.__contains__", |
| 24 | + "pandas._libs.hashtable.HashTable.__len__", |
| 25 | + "pandas._libs.hashtable.HashTable.factorize", |
| 26 | + "pandas._libs.hashtable.HashTable.get_item", |
| 27 | + "pandas._libs.hashtable.HashTable.get_labels", |
| 28 | + "pandas._libs.hashtable.HashTable.get_state", |
| 29 | + "pandas._libs.hashtable.HashTable.lookup", |
| 30 | + "pandas._libs.hashtable.HashTable.map_locations", |
| 31 | + "pandas._libs.hashtable.HashTable.set_item", |
| 32 | + "pandas._libs.hashtable.HashTable.sizeof", |
| 33 | + "pandas._libs.hashtable.HashTable.unique", |
| 34 | + # stubtest might be too sensitive |
| 35 | + "pandas._libs.lib.NoDefault", |
| 36 | + "pandas._libs.lib._NoDefault.no_default", |
| 37 | + # internal type alias (should probably be private) |
| 38 | + "pandas._libs.lib.ndarray_obj_2d", |
| 39 | + # workaround for mypy (cache_readonly = property) |
| 40 | + "pandas._libs.properties.cache_readonly.__get__", |
| 41 | + "pandas._libs.properties.cache_readonly.deleter", |
| 42 | + "pandas._libs.properties.cache_readonly.getter", |
| 43 | + "pandas._libs.properties.cache_readonly.setter", |
| 44 | + # TODO (child classes implement these methods) |
| 45 | + "pandas._libs.sparse.SparseIndex.__init__", |
| 46 | + "pandas._libs.sparse.SparseIndex.equals", |
| 47 | + "pandas._libs.sparse.SparseIndex.indices", |
| 48 | + "pandas._libs.sparse.SparseIndex.intersect", |
| 49 | + "pandas._libs.sparse.SparseIndex.lookup", |
| 50 | + "pandas._libs.sparse.SparseIndex.lookup_array", |
| 51 | + "pandas._libs.sparse.SparseIndex.make_union", |
| 52 | + "pandas._libs.sparse.SparseIndex.nbytes", |
| 53 | + "pandas._libs.sparse.SparseIndex.ngaps", |
| 54 | + "pandas._libs.sparse.SparseIndex.to_block_index", |
| 55 | + "pandas._libs.sparse.SparseIndex.to_int_index", |
| 56 | + # TODO (decorator changes argument names) |
| 57 | + "pandas._libs.tslibs.offsets.BaseOffset._apply_array", |
| 58 | + "pandas._libs.tslibs.offsets.BusinessHour.rollback", |
| 59 | + "pandas._libs.tslibs.offsets.BusinessHour.rollforward ", |
| 60 | + # type alias |
| 61 | + "pandas._libs.tslibs.timedeltas.UnitChoices", |
| 62 | +] |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + # find pyi files |
| 66 | + root = Path.cwd() |
| 67 | + pyi_modules = [ |
| 68 | + str(pyi.relative_to(root).with_suffix("")).replace(os.sep, ".") |
| 69 | + for pyi in root.glob("pandas/**/*.pyi") |
| 70 | + ] |
| 71 | + |
| 72 | + # create allowlist |
| 73 | + with tempfile.NamedTemporaryFile(mode="w+t") as allow: |
| 74 | + allow.write("\n".join(_ALLOWLIST)) |
| 75 | + allow.flush() |
| 76 | + |
| 77 | + args = pyi_modules + [ |
| 78 | + "--ignore-missing-stub", |
| 79 | + "--concise", |
| 80 | + "--mypy-config-file", |
| 81 | + "pyproject.toml", |
| 82 | + "--allowlist", |
| 83 | + allow.name, |
| 84 | + ] |
| 85 | + sys.exit(stubtest.test_stubs(stubtest.parse_options(args))) |
0 commit comments