-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use mypy
pre-commit in local environment
#1966
Merged
Merged
Changes from 44 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
8be02ed
add hypothesis and control mypy in pyproject.toml
EdAbati eb70be2
mypy in local
EdAbati 8e7990c
get_item tidy up draft
EdAbati 6ae4436
Merge remote-tracking branch 'upstream/main' into mypy-fixes
EdAbati 6017193
declaring relative path
EdAbati 86c23ed
pyproject fix
EdAbati 13745b4
restore precommit
EdAbati faa477b
add makefile
EdAbati b7aebab
skip mypy from precommit ci
EdAbati 75f474d
new typing CI
EdAbati 5f1aea6
add forgotten setup-python
EdAbati 2144196
where is mypy?
EdAbati 8664672
trying to create a venv
EdAbati 3aaf983
fix
EdAbati a030f61
trying again with PATH
EdAbati 9dbd938
always activate
EdAbati a4f6ae2
one more activate
EdAbati 46fade5
remove redundant which mypy
EdAbati 6bcea6b
force color?
EdAbati ce3eae9
force_color
EdAbati 4e09713
Merge branch 'main' into mypy-fixes
EdAbati 0ee5312
Merge branch 'main' into mypy-fixes
EdAbati 07532ba
env var check
EdAbati 57adae7
just mypy?
EdAbati 5689858
colors are not showing, giving up
EdAbati a6892e2
add polars only in mypy dependencies
EdAbati 96446f4
switching back to core
EdAbati 45deb67
calm down mypy a bit
EdAbati 5e03ed0
easy fix
EdAbati 9eec997
Merge branch 'main' into mypy-fixes
EdAbati 8c3fe94
some type fixes
EdAbati b301356
disable pyarrow-stubs
EdAbati 8698311
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4e63fcb
restore
EdAbati c22fd06
Merge branch 'main' into mypy-fixes
dangotbanned 9a2d9ff
Merge branch 'main' into mypy-fixes
EdAbati b9612cc
fix mypy version
EdAbati 8177933
organise optional dependencies
EdAbati 4456c33
add typing_extensions to tests
EdAbati 5dcdc1a
Merge remote-tracking branch 'upstream/main' into mypy-fixes
EdAbati 0dfed72
fix downstream tests
EdAbati 58ed0bf
fix last types
EdAbati 99a6690
add tests reqs
EdAbati 81ee931
Merge branch 'main' into mypy-fixes
EdAbati bf9e0d9
fix(typing): resolve some new `_duckdb.expr` warnings
dangotbanned 338962c
chore(typing): add stub ignore
dangotbanned 9abdd34
Merge remote-tracking branch 'upstream/main' into pr/EdAbati/1966
dangotbanned 54a29c7
fix(typing): widen annotation to inclide `_1DArray`
dangotbanned 5306ce2
refactor: replace `ConstantExpression` w/ `lit` alias
dangotbanned 6fc845e
fix(typing): resolve `_duckdb` `[operator]` warnings
dangotbanned 1dd6d98
revert(typing): undo "fixes" for `ddof`
dangotbanned fd192f2
chore(typing): resolve `PandasLikeSeries.hist` warnings
dangotbanned 53a8dda
fix(typing): resolve 26 `pyright` warnings
dangotbanned 9f87adf
Merge branch 'main' into mypy-fixes
dangotbanned 59b7ba5
refactor(typing): replace `NoReturn` w/ `Never`
dangotbanned e7a8494
Merge remote-tracking branch 'upstream/main' into pr/EdAbati/1966
dangotbanned File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Type checking | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
mypy: | ||
strategy: | ||
matrix: | ||
python-version: ["3.11"] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install uv | ||
uses: astral-sh/setup-uv@v5 | ||
with: | ||
enable-cache: "true" | ||
cache-suffix: ${{ matrix.python-version }} | ||
cache-dependency-glob: "pyproject.toml" | ||
- name: Create venv | ||
run: uv venv .venv | ||
- name: install-reqs | ||
# TODO: add more dependencies/backends incrementally | ||
run: | | ||
source .venv/bin/activate | ||
uv pip install -e ".[tests, typing, core]" | ||
- name: show-deps | ||
run: | | ||
source .venv/bin/activate | ||
uv pip freeze | ||
- name: Run mypy | ||
run: | | ||
source .venv/bin/activate | ||
make typing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Mostly based on polars Makefile | ||
# https://github.com/pola-rs/polars/blob/main/py-polars/Makefile | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
SHELL=bash | ||
VENV=./.venv | ||
|
||
ifeq ($(OS),Windows_NT) | ||
VENV_BIN=$(VENV)/Scripts | ||
else | ||
VENV_BIN=$(VENV)/bin | ||
endif | ||
|
||
|
||
.PHONY: help | ||
help: ## Display this help screen | ||
@echo -e "\033[1mAvailable commands:\033[0m" | ||
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}' | sort | ||
|
||
.PHONY: typing | ||
typing: ## Run typing checks | ||
$(VENV_BIN)/mypy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
from narwhals.utils import Version | ||
|
||
|
||
class DuckDBExpr(CompliantExpr["duckdb.Expression"]): | ||
class DuckDBExpr(CompliantExpr["duckdb.Expression"]): # type: ignore[type-var] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ignore should actually be solved. Is it ok for a follow-up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup definitely |
||
_implementation = Implementation.DUCKDB | ||
_depth = 0 # Unused, just for compatibility with CompliantExpr | ||
|
||
|
@@ -312,13 +312,16 @@ def skew(self: Self) -> Self: | |
def func(_input: duckdb.Expression) -> duckdb.Expression: | ||
count = FunctionExpression("count", _input) | ||
return CaseExpression( | ||
condition=count == 0, value=ConstantExpression(None) | ||
condition=count == 0, # type: ignore[arg-type] | ||
value=ConstantExpression(None), | ||
).otherwise( | ||
CaseExpression( | ||
condition=count == 1, value=ConstantExpression(float("nan")) | ||
condition=count == 1, # type: ignore[arg-type] | ||
value=ConstantExpression(float("nan")), | ||
).otherwise( | ||
CaseExpression( | ||
condition=count == 2, value=ConstantExpression(0.0) | ||
condition=count == 2, # type: ignore[arg-type] | ||
value=ConstantExpression(0.0), | ||
).otherwise(FunctionExpression("skewness", _input)) | ||
) | ||
) | ||
|
@@ -427,7 +430,7 @@ def _std(_input: duckdb.Expression, ddof: int) -> duckdb.Expression: | |
return ( | ||
FunctionExpression("stddev_pop", _input) | ||
* FunctionExpression("sqrt", n_samples) | ||
/ (FunctionExpression("sqrt", (n_samples - ddof))) | ||
/ (FunctionExpression("sqrt", (n_samples - ddof))) # type: ignore[operator] | ||
) | ||
|
||
return self._from_call( | ||
|
@@ -440,7 +443,7 @@ def _std(_input: duckdb.Expression, ddof: int) -> duckdb.Expression: | |
def var(self: Self, ddof: int) -> Self: | ||
def _var(_input: duckdb.Expression, ddof: int) -> duckdb.Expression: | ||
n_samples = FunctionExpression("count", _input) | ||
return FunctionExpression("var_pop", _input) * n_samples / (n_samples - ddof) | ||
return FunctionExpression("var_pop", _input) * n_samples / (n_samples - ddof) # type: ignore[operator] | ||
|
||
return self._from_call( | ||
_var, | ||
|
@@ -521,7 +524,7 @@ def fill_null(self: Self, value: Any, strategy: Any, limit: int | None) -> Self: | |
def cast(self: Self, dtype: DType | type[DType]) -> Self: | ||
def func(_input: duckdb.Expression) -> duckdb.Expression: | ||
native_dtype = narwhals_to_native_dtype(dtype, self._version) | ||
return _input.cast(native_dtype) | ||
return _input.cast(native_dtype) # type: ignore[arg-type] | ||
|
||
return self._from_call( | ||
func, | ||
|
dangotbanned marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on the duckdb stubs, only
str
are allowed in.aggregate
. π€There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks wrong, it should be
str | list[Expression]
, right? want to make a PR to duckdb?