From c8a5a70e3a06ebee96664cefe5b59e0449a36f1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:26:07 +0000 Subject: [PATCH 1/5] chore(python): Bump mypy from 1.11.1 to 1.13.0 in /py-polars Bumps [mypy](https://github.com/python/mypy) from 1.11.1 to 1.13.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v1.11.1...v1.13.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- py-polars/requirements-lint.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py-polars/requirements-lint.txt b/py-polars/requirements-lint.txt index 7d3535b0a08c..84ae5ba7bb6e 100644 --- a/py-polars/requirements-lint.txt +++ b/py-polars/requirements-lint.txt @@ -1,3 +1,3 @@ -mypy==1.11.1 +mypy==1.13.0 ruff==0.7.1 typos==1.26.8 From 410d80c0d24cfd33fa2fe18f321e0ccc2acf812d Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 1 Nov 2024 16:27:36 +0100 Subject: [PATCH 2/5] Remove unused ignores --- py-polars/polars/dataframe/frame.py | 4 ++-- py-polars/polars/datatypes/convert.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index 721a02c7fec6..1bbd8f85700f 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -4853,7 +4853,7 @@ def glimpse( def _parse_column(col_name: str, dtype: PolarsDataType) -> tuple[str, str, str]: fn = repr if schema[col_name] == String else str values = self[:max_n_values, col_name].to_list() - val_str = ", ".join(fn(v) for v in values) # type: ignore[operator] + val_str = ", ".join(fn(v) for v in values) if len(col_name) > max_colname_length: col_name = col_name[: (max_colname_length - 1)] + "…" return col_name, f"<{_dtype_str_repr(dtype)}>", val_str @@ -9902,7 +9902,7 @@ def n_unique(self, subset: str | Expr | Sequence[str | Expr] | None = None) -> i expr = wrap_expr(parse_into_expression(subset[0])) else: struct_fields = F.all() if (subset is None) else subset - expr = F.struct(struct_fields) # type: ignore[call-overload] + expr = F.struct(struct_fields) df = self.lazy().select(expr.n_unique()).collect(_eager=True) return 0 if df.is_empty() else df.row(0)[0] diff --git a/py-polars/polars/datatypes/convert.py b/py-polars/polars/datatypes/convert.py index f773cc28b6ca..423c687833ca 100644 --- a/py-polars/polars/datatypes/convert.py +++ b/py-polars/polars/datatypes/convert.py @@ -72,7 +72,7 @@ def is_polars_dtype( ) -> TypeGuard[PolarsDataType]: """Indicate whether the given input is a Polars dtype, or dtype specialization.""" check_classes = DataType if require_instantiated else (DataType, DataTypeClass) - is_dtype = isinstance(dtype, check_classes) # type: ignore[arg-type] + is_dtype = isinstance(dtype, check_classes) if not include_unknown: return is_dtype and dtype != Unknown From c4079e42f7cca4273e9380b4bf4097b957bd0ee2 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 1 Nov 2024 19:02:05 +0100 Subject: [PATCH 3/5] Enable mypy optimization --- py-polars/requirements-lint.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py-polars/requirements-lint.txt b/py-polars/requirements-lint.txt index 84ae5ba7bb6e..b6c173bf8320 100644 --- a/py-polars/requirements-lint.txt +++ b/py-polars/requirements-lint.txt @@ -1,3 +1,3 @@ -mypy==1.13.0 +mypy[faster-cache]==1.13.0 ruff==0.7.1 typos==1.26.8 From 653393ddca70c544f5d2fdb19ee170e86085eb98 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 1 Nov 2024 20:55:04 +0100 Subject: [PATCH 4/5] Fix some types --- py-polars/polars/expr/expr.py | 2 +- py-polars/polars/functions/lazy.py | 8 +++++--- py-polars/polars/lazyframe/frame.py | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index 4613aabd4beb..b9a15dd1d24d 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -310,7 +310,7 @@ def __array_ufunc__( root_expr = F.struct(actual_exprs) def function(s: Series) -> Series: # pragma: no cover - args = [] + args: list[Any] = [] for i, expr in enumerate(exprs): if expr[1] and num_expr > 1: args.append(s.struct[i]) diff --git a/py-polars/polars/functions/lazy.py b/py-polars/polars/functions/lazy.py index 7a473048bc23..dfd3f607791c 100644 --- a/py-polars/polars/functions/lazy.py +++ b/py-polars/polars/functions/lazy.py @@ -1867,9 +1867,11 @@ def collect_all_async( ) prepared.append(ldf) - result = _GeventDataFrameResult() if gevent else _AioDataFrameResult() - plr.collect_all_with_callback(prepared, result._callback_all) # type: ignore[attr-defined] - return result # type: ignore[return-value] + result: ( + _GeventDataFrameResult[list[DataFrame]] | _AioDataFrameResult[list[DataFrame]] + ) = _GeventDataFrameResult() if gevent else _AioDataFrameResult() + plr.collect_all_with_callback(prepared, result._callback_all) + return result def select(*exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr) -> DataFrame: diff --git a/py-polars/polars/lazyframe/frame.py b/py-polars/polars/lazyframe/frame.py index 64608ae825fb..f8d335161db0 100644 --- a/py-polars/polars/lazyframe/frame.py +++ b/py-polars/polars/lazyframe/frame.py @@ -2229,9 +2229,11 @@ def collect_async( new_streaming=False, ) - result = _GeventDataFrameResult() if gevent else _AioDataFrameResult() - ldf.collect_with_callback(result._callback) # type: ignore[attr-defined] - return result # type: ignore[return-value] + result: _GeventDataFrameResult[DataFrame] | _AioDataFrameResult[DataFrame] = ( + _GeventDataFrameResult() if gevent else _AioDataFrameResult() + ) + ldf.collect_with_callback(result._callback) + return result def collect_schema(self) -> Schema: """ From ec98d44db52004e4bec5db5e484610560979472e Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Fri, 1 Nov 2024 21:40:35 +0100 Subject: [PATCH 5/5] Add ignores for connection types --- py-polars/polars/dataframe/frame.py | 8 ++++---- py-polars/polars/io/database/_executor.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/py-polars/polars/dataframe/frame.py b/py-polars/polars/dataframe/frame.py index 1bbd8f85700f..3403f8c12dac 100644 --- a/py-polars/polars/dataframe/frame.py +++ b/py-polars/polars/dataframe/frame.py @@ -3990,13 +3990,13 @@ def unpack_table_name(name: str) -> tuple[str | None, str | None, str]: else (connection, False) ) with ( - conn if can_close_conn else contextlib.nullcontext(), - conn.cursor() as cursor, + conn if can_close_conn else contextlib.nullcontext(), # type: ignore[union-attr] + conn.cursor() as cursor, # type: ignore[union-attr] ): catalog, db_schema, unpacked_table_name = unpack_table_name(table_name) n_rows: int if adbc_version >= (0, 7): - if "sqlite" in conn.adbc_get_info()["driver_name"].lower(): + if "sqlite" in conn.adbc_get_info()["driver_name"].lower(): # type: ignore[union-attr] if if_table_exists == "replace": # note: adbc doesn't (yet) support 'replace' for sqlite cursor.execute(f"DROP TABLE IF EXISTS {table_name}") @@ -4026,7 +4026,7 @@ def unpack_table_name(name: str) -> tuple[str | None, str | None, str]: mode=mode, **(engine_options or {}), ) - conn.commit() + conn.commit() # type: ignore[union-attr] return n_rows elif engine == "sqlalchemy": diff --git a/py-polars/polars/io/database/_executor.py b/py-polars/polars/io/database/_executor.py index cb6b6b92ff1b..1cbaf4679db9 100644 --- a/py-polars/polars/io/database/_executor.py +++ b/py-polars/polars/io/database/_executor.py @@ -422,7 +422,7 @@ async def _sqlalchemy_async_execute(self, query: TextClause, **options: Any) -> """Execute a query using an async SQLAlchemy connection.""" is_session = self._is_alchemy_session(self.cursor) cursor = self.cursor.begin() if is_session else self.cursor # type: ignore[attr-defined] - async with cursor as conn: + async with cursor as conn: # type: ignore[union-attr] if is_session and not hasattr(conn, "execute"): conn = conn.session result = await conn.execute(query, **options)