From fba101c20af0cab5884647ffcd6c381e2df5c9fb Mon Sep 17 00:00:00 2001 From: J van Zundert Date: Sun, 24 Jul 2022 11:06:09 +0200 Subject: [PATCH] Mypy disallow untyped calls (#4099) Thanks @zundertj. --- .github/workflows/test-python.yaml | 48 ++++++++++++++++++++++++++- py-polars/polars/internals/series.py | 2 +- py-polars/pyproject.toml | 2 +- py-polars/test.parquet | Bin 0 -> 860 bytes py-polars/tests/test_df.py | 10 +++--- 5 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 py-polars/test.parquet diff --git a/.github/workflows/test-python.yaml b/.github/workflows/test-python.yaml index cedc5c14c7b07..afa8f00f92d52 100644 --- a/.github/workflows/test-python.yaml +++ b/.github/workflows/test-python.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.7", "3.10" ] + python-version: [ "3.10" ] steps: - uses: actions/checkout@v3 - name: Install latest Rust nightly @@ -51,3 +51,49 @@ jobs: run: | pip uninstall pandas -y python -c "import polars" + + test-python-37: + name: Build and test Python 3.7 + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.7" ] + steps: + - uses: actions/checkout@v3 + - name: Install latest Rust nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly-2022-06-22 + override: true + components: rustfmt, clippy + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r py-polars/build.requirements.txt + - name: Run formatting checks + run: | + cd py-polars && black --check . && blackdoc --check . && isort --check . && rustup override set nightly-2022-06-22 && cargo fmt --all -- --check && cd .. + - name: Run linting + run: | + cd py-polars && flake8 && cd .. + # this step is different, note the flag + - name: Run type checking + run: | + cd py-polars && mypy --allow-untyped-calls && cd .. + - name: Run tests + run: | + export RUSTFLAGS="-C debuginfo=0" + cd py-polars && rustup override set nightly-2022-06-22 && make venv && make test-with-cov + cargo clippy + - name: Check doc examples + run: | + cd py-polars && make doctest + # test if we can import polars without any requirements + - name: Import polars + run: | + pip uninstall pandas -y + python -c "import polars" \ No newline at end of file diff --git a/py-polars/polars/internals/series.py b/py-polars/polars/internals/series.py index cea778abd1572..bd364f85aacbb 100644 --- a/py-polars/polars/internals/series.py +++ b/py-polars/polars/internals/series.py @@ -2296,7 +2296,7 @@ def to_numpy( kwargs will be sent to pyarrow.Array.to_numpy """ - def convert_to_date(arr): # type: ignore[no-untyped-def] + def convert_to_date(arr: np.ndarray) -> np.ndarray: if self.dtype == Date: tp = "datetime64[D]" elif self.dtype == Duration: diff --git a/py-polars/pyproject.toml b/py-polars/pyproject.toml index 017db10bd42ed..a22054510cb67 100644 --- a/py-polars/pyproject.toml +++ b/py-polars/pyproject.toml @@ -35,7 +35,7 @@ warn_unused_ignores = true strict_concatenate = true # TODO: Uncomment flags below and fix mypy errors # disallow_any_generics = true -# disallow_untyped_calls = true +disallow_untyped_calls = true warn_redundant_casts = true # warn_return_any = true # no_implicit_reexport = true diff --git a/py-polars/test.parquet b/py-polars/test.parquet new file mode 100644 index 0000000000000000000000000000000000000000..7257e1be465191fc1bd3cdff7a368339d23e1ffd GIT binary patch literal 860 zcmbVLO;6iE5Z$%iG>RewQg&ra7PU}gRe~x|2nvWpCm%qmOKcaBf^tFNhDZrUwn+-7 z9#BTl|AsQNp4>bWx;qn>){NV_}pcHWzrmDY!FO%%j);q-+e*yCDYOxKq< zW+n`)$_keGWRS!+*J4f@(wClFB+jB(@=yg6e<6i2psh(;3*oYu>x&YKm&803Sg<$Q z3*It0V1oYawWe1zQMT%=FmE-Urdi?*)65vrHq4?imMY16E+4r2h41{OTDB|-Pof5T z-?=y>7rX558%Z2z!oZ-a<^8g{WD{3VI8WLJI)T0G55cpHAui4ZtAJLl;^x1tbLBJ4{+uB9{tOdCgr!Q1LzK;2Gxp zcX=IEY?JiY6iLOT49%R6E`mMc?*beXzfFO%_69O*7^4lSU$g+WXr5aY;C4cI2Yl+U zfl|S&-@Vc5X>U~})zo|n-zVUFJ-j{I8{J(%J0<-tfiv+Fav{JDap=wfb?FS~U4Z&h zwncg~Y4tQnJ)pXH;s^kz>j#sI4*<+ufh38iubh|8;aN7EL{4~ None: df = pl.DataFrame({"a": [1, 1, 3, 4], "b": [1, 1, 2, 2]}) class Foo: - def __init__(self): # type: ignore[no-untyped-def] + def __init__(self) -> None: pass - def __hash__(self): # type: ignore[no-untyped-def] + def __hash__(self) -> int: return 0 - def __eq__(self, other): # type: ignore[no-untyped-def] + def __eq__(self, other: Any) -> bool: return True df = df.with_column(pl.col("a").apply(lambda x: Foo()).alias("foo")) @@ -1304,10 +1304,10 @@ def name_generator() -> Iterator[str]: def test_extension() -> None: class Foo: - def __init__(self, value): # type: ignore[no-untyped-def] + def __init__(self, value: Any) -> None: self.value = value - def __repr__(self): # type: ignore[no-untyped-def] + def __repr__(self) -> str: return f"foo({self.value})" foos = [Foo(1), Foo(2), Foo(3)]