Skip to content

Commit 17cf983

Browse files
authored
test(typing): Avoid masking fixed overloads (#3033)
1 parent 3c58b0e commit 17cf983

File tree

6 files changed

+14
-27
lines changed

6 files changed

+14
-27
lines changed

tests/expr_and_series/rolling_var_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import random
4-
from typing import TYPE_CHECKING, Any
4+
from typing import Any
55

66
import hypothesis.strategies as st
77
import pytest
@@ -17,9 +17,6 @@
1717
assert_equal_data,
1818
)
1919

20-
if TYPE_CHECKING:
21-
from narwhals.typing import Frame
22-
2320
pytest.importorskip("pandas")
2421
import pandas as pd
2522

@@ -125,7 +122,7 @@ def test_rolling_var_hypothesis(center: bool, values: list[float]) -> None: # n
125122
.to_frame("a")
126123
)
127124

128-
result: Frame = nw.from_native(pa.Table.from_pandas(df)).select(
125+
result = nw.from_native(pa.Table.from_pandas(df)).select(
129126
nw.col("a").rolling_var(
130127
window_size, center=center, min_samples=min_samples, ddof=ddof
131128
)

tests/frame/invalid_test.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
from narwhals.exceptions import MultiOutputExpressionError
1010
from tests.utils import NUMPY_VERSION, POLARS_VERSION, Constructor
1111

12-
if TYPE_CHECKING:
13-
from narwhals.typing import Frame
14-
15-
1612
T = TypeVar("T")
1713

1814

@@ -21,14 +17,14 @@
2117
)
2218
def test_all_vs_all(constructor: Constructor) -> None:
2319
data = {"a": [1, 3, 2], "b": [4, 4, 6]}
24-
df: Frame = nw.from_native(constructor(data))
20+
df = nw.from_native(constructor(data))
2521
with pytest.raises(MultiOutputExpressionError):
2622
df.lazy().select(nw.all() + nw.col("b", "a")).collect()
2723

2824

2925
def test_invalid() -> None:
3026
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8.0, 9.0]}
31-
df: Frame = nw.from_native(pd.DataFrame(data))
27+
df = nw.from_native(pd.DataFrame(data))
3228
with pytest.raises(ValueError, match="Multi-output"):
3329
df.select(nw.all() + nw.all())
3430

@@ -37,7 +33,7 @@ def test_invalid_pyarrow() -> None:
3733
pytest.importorskip("pyarrow")
3834
import pyarrow as pa
3935

40-
df: Frame = nw.from_native(pa.table({"a": [1, 2], "b": [3, 4]}))
36+
df = nw.from_native(pa.table({"a": [1, 2], "b": [3, 4]}))
4137
with pytest.raises(MultiOutputExpressionError):
4238
df.select(nw.all() + nw.all())
4339

@@ -47,7 +43,7 @@ def test_invalid_polars() -> None:
4743
import polars as pl
4844

4945
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8.0, 9.0]}
50-
df: Frame = nw.from_native(pd.DataFrame(data))
46+
df = nw.from_native(pd.DataFrame(data))
5147
with pytest.raises(TypeError, match="Perhaps you"):
5248
df.select([pl.col("a")]) # type: ignore[list-item]
5349
with pytest.raises(TypeError, match="Expected Narwhals dtype"):

tests/series_only/is_ordered_categorical_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from tests.utils import POLARS_VERSION
1010

1111
if TYPE_CHECKING:
12-
from narwhals.typing import IntoSeries
1312
from tests.utils import ConstructorEager
1413

1514

@@ -33,7 +32,6 @@ def test_is_ordered_categorical_polars() -> None:
3332
pytest.importorskip("polars")
3433
import polars as pl
3534

36-
s: IntoSeries | Any
3735
s = pl.Series(["a", "b"], dtype=pl.Categorical)
3836
if POLARS_VERSION < (1, 32): # pragma: no cover
3937
assert nw.is_ordered_categorical(nw.from_native(s, series_only=True))

tests/translate/get_native_namespace_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import narwhals as nw
88

99
if TYPE_CHECKING:
10-
from narwhals.typing import Frame
11-
from tests.utils import Constructor
10+
from tests.utils import Constructor, ConstructorEager
1211

1312

1413
data = {"a": [1, 2, 3]}
@@ -62,18 +61,18 @@ def test_native_namespace_frame(constructor: Constructor) -> None:
6261

6362
expected_namespace = _get_expected_namespace(constructor_name=constructor_name)
6463

65-
df: Frame = nw.from_native(constructor(data))
64+
df = nw.from_native(constructor(data))
6665
assert nw.get_native_namespace(df) is expected_namespace
6766
assert nw.get_native_namespace(df.to_native()) is expected_namespace
6867
assert nw.get_native_namespace(df.lazy().to_native()) is expected_namespace
6968

7069

71-
def test_native_namespace_series(constructor_eager: Constructor) -> None:
70+
def test_native_namespace_series(constructor_eager: ConstructorEager) -> None:
7271
constructor_name = constructor_eager.__name__
7372

7473
expected_namespace = _get_expected_namespace(constructor_name=constructor_name)
7574

76-
df: Frame = nw.from_native(constructor_eager(data), eager_only=True)
75+
df = nw.from_native(constructor_eager(data), eager_only=True)
7776

7877
assert nw.get_native_namespace(df["a"].to_native()) is expected_namespace
7978
assert nw.get_native_namespace(df, df["a"].to_native()) is expected_namespace

tests/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,9 @@ def uses_pyarrow_backend(constructor: Constructor | ConstructorEager) -> bool:
210210

211211

212212
def maybe_collect(df: Frame) -> Frame:
213-
"""Collect the DataFrame if it is a LazyFrame.
213+
"""Collect to DataFrame if it is a LazyFrame.
214214
215215
Use this function to test specific behaviors during collection.
216216
For example, Polars only errors when we call `collect` in the lazy case.
217217
"""
218-
if isinstance(df, nw.LazyFrame):
219-
return df.collect()
220-
return df # pragma: no cover
218+
return df.collect() if isinstance(df, nw.LazyFrame) else df

tests/utils_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
from narwhals._utils import _SupportsVersion
3535
from narwhals.series import Series
36-
from narwhals.typing import IntoSeries
3736

3837

3938
@dataclass
@@ -126,7 +125,7 @@ def test_maybe_set_index_polars_column_names(
126125
],
127126
)
128127
def test_maybe_set_index_pandas_direct_index(
129-
narwhals_index: Series[IntoSeries] | list[Series[IntoSeries]],
128+
narwhals_index: Series[pd.Series[Any]] | list[Series[pd.Series[Any]]],
130129
pandas_index: pd.Series[Any] | list[pd.Series[Any]],
131130
native_df_or_series: pd.DataFrame | pd.Series[Any],
132131
) -> None:
@@ -151,7 +150,7 @@ def test_maybe_set_index_pandas_direct_index(
151150
],
152151
)
153152
def test_maybe_set_index_polars_direct_index(
154-
index: Series[IntoSeries] | list[Series[IntoSeries]] | None,
153+
index: Series[pd.Series[Any]] | list[Series[pd.Series[Any]]] | None,
155154
) -> None:
156155
pytest.importorskip("polars")
157156
import polars as pl

0 commit comments

Comments
 (0)