Skip to content

Commit 41475ad

Browse files
authored
chore(typing): fix/ignore utils, tpch warnings (#2426)
* chore(typing): fix `check_docstrings` `Path` warning `pyright` did a good job spotting that one * chore: Use `dir(...)` instead of `.__dir__()` Fixes 2/6 errors and shrinks the script * chore(typing): Fix 2 more errors These have been popping up and bugging me for 2 weeks 🙈 #2351 (comment) * chore(typing): Fix the last 2 as well * chore: Simplify the rest * chore(typing): Ignore remaining in `utils` * chore(typing): Ignore everything in `tpch` These are all the same issue, can be fixed with a constrained `TypeVar` * fix: pre-`3.13` compat? Following where `__name__` used to be sourced from - python/cpython#101876 * chore(typing): Fix some of the new `tpch` ignores The rest seem pretty unavoidable * fix: don't clobber `typing` 🤦‍♂️ https://github.com/narwhals-dev/narwhals/actions/runs/14624570842/job/41032838053?pr=2426
1 parent 1e41b0e commit 41475ad

28 files changed

+108
-107
lines changed

tpch/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from __future__ import annotations
2+
3+
from tpch import _typing
4+
5+
__all__ = ["_typing"]

tpch/_typing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
from typing import TypeVar
5+
6+
from narwhals import DataFrame
7+
from narwhals import LazyFrame
8+
9+
FrameT = TypeVar("FrameT", DataFrame[Any], LazyFrame[Any])

tpch/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import narwhals as nw
1717

1818
pd.options.mode.copy_on_write = True
19-
pd.options.future.infer_string = True
19+
pd.options.future.infer_string = True # pyright: ignore[reportAttributeAccessIssue, reportOptionalMemberAccess]
2020
pl.Config.set_fmt_float("full")
2121

2222
DATA_DIR = Path("data")

tpch/queries/q1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import narwhals as nw
77

88
if TYPE_CHECKING:
9-
from narwhals.typing import FrameT
9+
from tpch._typing import FrameT
1010

1111

1212
def query(lineitem: FrameT) -> FrameT:

tpch/queries/q10.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import narwhals as nw
77

88
if TYPE_CHECKING:
9-
from narwhals.typing import FrameT
9+
from tpch._typing import FrameT
1010

1111

1212
def query(

tpch/queries/q11.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import narwhals as nw
66

77
if TYPE_CHECKING:
8-
from narwhals.typing import FrameT
8+
from tpch._typing import FrameT
99

1010

1111
def query(
@@ -30,7 +30,7 @@ def query(
3030
q1.with_columns((nw.col("ps_supplycost") * nw.col("ps_availqty")).alias("value"))
3131
.group_by("ps_partkey")
3232
.agg(nw.sum("value"))
33-
.join(q2, how="cross")
33+
.join(q2, how="cross") # pyright: ignore[reportArgumentType]
3434
.filter(nw.col("value") > nw.col("tmp"))
3535
.select("ps_partkey", "value")
3636
.sort("value", descending=True)

tpch/queries/q12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import narwhals as nw
77

88
if TYPE_CHECKING:
9-
from narwhals.typing import FrameT
9+
from tpch._typing import FrameT
1010

1111

1212
def query(line_item_ds: FrameT, orders_ds: FrameT) -> FrameT:

tpch/queries/q13.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import narwhals as nw
66

77
if TYPE_CHECKING:
8-
from narwhals.typing import FrameT
8+
from tpch._typing import FrameT
99

1010

1111
def query(customer_ds: FrameT, orders_ds: FrameT) -> FrameT:
@@ -14,7 +14,7 @@ def query(customer_ds: FrameT, orders_ds: FrameT) -> FrameT:
1414

1515
orders = orders_ds.filter(~nw.col("o_comment").str.contains(f"{var1}.*{var2}"))
1616
return (
17-
customer_ds.join(orders, left_on="c_custkey", right_on="o_custkey", how="left")
17+
customer_ds.join(orders, left_on="c_custkey", right_on="o_custkey", how="left") # pyright: ignore[reportArgumentType]
1818
.group_by("c_custkey")
1919
.agg(nw.col("o_orderkey").count().alias("c_count"))
2020
.group_by("c_count")

tpch/queries/q14.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import narwhals as nw
77

88
if TYPE_CHECKING:
9-
from narwhals.typing import FrameT
9+
from tpch._typing import FrameT
1010

1111

1212
def query(line_item_ds: FrameT, part_ds: FrameT) -> FrameT:

tpch/queries/q15.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import narwhals as nw
77

88
if TYPE_CHECKING:
9-
from narwhals.typing import FrameT
9+
from tpch._typing import FrameT
1010

1111

1212
def query(
@@ -29,7 +29,7 @@ def query(
2929
)
3030

3131
return (
32-
supplier_ds.join(revenue, left_on="s_suppkey", right_on="supplier_no")
32+
supplier_ds.join(revenue, left_on="s_suppkey", right_on="supplier_no") # pyright: ignore[reportArgumentType]
3333
.filter(nw.col("total_revenue") == nw.col("total_revenue").max())
3434
.with_columns(nw.col("total_revenue").round(2))
3535
.select("s_suppkey", "s_name", "s_address", "s_phone", "total_revenue")

0 commit comments

Comments
 (0)