Skip to content

Commit 1d6fd0c

Browse files
committed
rollback dict annotation?
1 parent 4952021 commit 1d6fd0c

File tree

4 files changed

+22
-55
lines changed

4 files changed

+22
-55
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ convention = "google"
9494

9595
[tool.ruff.lint.isort]
9696
force-single-line = true
97+
required-imports = ["from __future__ import annotations"]
9798

9899
[tool.ruff.format]
99100
docstring-code-format = true

tests/conftest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,47 +48,47 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> Any: # pragma: no
4848
item.add_marker(skip_slow)
4949

5050

51-
def pandas_constructor(obj: dict[str, Any]) -> IntoDataFrame:
51+
def pandas_constructor(obj: Any) -> IntoDataFrame:
5252
return pd.DataFrame(obj) # type: ignore[no-any-return]
5353

5454

55-
def pandas_nullable_constructor(obj: dict[str, Any]) -> IntoDataFrame:
55+
def pandas_nullable_constructor(obj: Any) -> IntoDataFrame:
5656
return pd.DataFrame(obj).convert_dtypes(dtype_backend="numpy_nullable") # type: ignore[no-any-return]
5757

5858

59-
def pandas_pyarrow_constructor(obj: dict[str, Any]) -> IntoDataFrame:
59+
def pandas_pyarrow_constructor(obj: Any) -> IntoDataFrame:
6060
return pd.DataFrame(obj).convert_dtypes(dtype_backend="pyarrow") # type: ignore[no-any-return]
6161

6262

63-
def modin_constructor(obj: dict[str, Any]) -> IntoDataFrame: # pragma: no cover
63+
def modin_constructor(obj: Any) -> IntoDataFrame: # pragma: no cover
6464
mpd = get_modin()
6565
return mpd.DataFrame(pd.DataFrame(obj)).convert_dtypes(dtype_backend="pyarrow") # type: ignore[no-any-return]
6666

6767

68-
def cudf_constructor(obj: dict[str, Any]) -> IntoDataFrame: # pragma: no cover
68+
def cudf_constructor(obj: Any) -> IntoDataFrame: # pragma: no cover
6969
cudf = get_cudf()
7070
return cudf.DataFrame(obj) # type: ignore[no-any-return]
7171

7272

73-
def polars_eager_constructor(obj: dict[str, Any]) -> IntoDataFrame:
73+
def polars_eager_constructor(obj: Any) -> IntoDataFrame:
7474
return pl.DataFrame(obj)
7575

7676

77-
def polars_lazy_constructor(obj: dict[str, Any]) -> pl.LazyFrame:
77+
def polars_lazy_constructor(obj: Any) -> pl.LazyFrame:
7878
return pl.LazyFrame(obj)
7979

8080

81-
def dask_lazy_p1_constructor(obj: dict[str, Any]) -> IntoFrame: # pragma: no cover
81+
def dask_lazy_p1_constructor(obj: Any) -> IntoFrame: # pragma: no cover
8282
dd = get_dask_dataframe()
8383
return dd.from_dict(obj, npartitions=1) # type: ignore[no-any-return]
8484

8585

86-
def dask_lazy_p2_constructor(obj: dict[str, Any]) -> IntoFrame: # pragma: no cover
86+
def dask_lazy_p2_constructor(obj: Any) -> IntoFrame: # pragma: no cover
8787
dd = get_dask_dataframe()
8888
return dd.from_dict(obj, npartitions=2) # type: ignore[no-any-return]
8989

9090

91-
def pyarrow_table_constructor(obj: dict[str, Any]) -> IntoDataFrame:
91+
def pyarrow_table_constructor(obj: Any) -> IntoDataFrame:
9292
return pa.table(obj) # type: ignore[no-any-return]
9393

9494

@@ -115,7 +115,7 @@ def pyarrow_table_constructor(obj: dict[str, Any]) -> IntoDataFrame:
115115
@pytest.fixture(params=eager_constructors)
116116
def constructor_eager(
117117
request: pytest.FixtureRequest,
118-
) -> Callable[[dict[str, Any]], IntoDataFrame]:
118+
) -> Callable[[Any], IntoDataFrame]:
119119
return request.param # type: ignore[no-any-return]
120120

121121

tests/frame/rows_test.py

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,15 @@
44
from typing import Any
55

66
import pandas as pd
7-
import polars as pl
8-
import pyarrow as pa
97
import pytest
108

119
import narwhals.stable.v1 as nw
12-
from narwhals.utils import parse_version
1310

1411
if TYPE_CHECKING:
1512
from tests.utils import ConstructorEager
1613

17-
df_pandas = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
18-
df_pa = pa.table({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
19-
if parse_version(pd.__version__) >= parse_version("1.5.0"):
20-
df_pandas_pyarrow = pd.DataFrame(
21-
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
22-
).astype(
23-
{
24-
"a": "Int64[pyarrow]",
25-
"b": "Int64[pyarrow]",
26-
"z": "Float64[pyarrow]",
27-
}
28-
)
29-
df_pandas_nullable = pd.DataFrame(
30-
{"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
31-
).astype(
32-
{
33-
"a": "Int64",
34-
"b": "Int64",
35-
"z": "Float64",
36-
}
37-
)
38-
else: # pragma: no cover
39-
df_pandas_pyarrow = df_pandas
40-
df_pandas_nullable = df_pandas
41-
df_polars = pl.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
42-
43-
df_pandas_na = pd.DataFrame({"a": [None, 3, 2], "b": [4, 4, 6], "z": [7.0, None, 9]})
44-
df_polars_na = pl.DataFrame({"a": [None, 3, 2], "b": [4, 4, 6], "z": [7.0, None, 9]})
14+
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
15+
data_na = {"a": [None, 3, 2], "b": [4, 4, 6], "z": [7.0, None, 9]}
4516

4617

4718
@pytest.mark.parametrize(
@@ -73,9 +44,6 @@ def test_iter_rows(
7344
assert result == expected
7445

7546

76-
@pytest.mark.parametrize(
77-
"df_raw", [df_pandas, df_pandas_nullable, df_pandas_pyarrow, df_polars, df_pa]
78-
)
7947
@pytest.mark.parametrize(
8048
("named", "expected"),
8149
[
@@ -91,19 +59,18 @@ def test_iter_rows(
9159
],
9260
)
9361
def test_rows(
94-
df_raw: Any,
62+
constructor_eager: ConstructorEager,
9563
named: bool, # noqa: FBT001
9664
expected: list[tuple[Any, ...]] | list[dict[str, Any]],
9765
) -> None:
98-
df = nw.from_native(df_raw, eager_only=True)
66+
df = nw.from_native(constructor_eager(data), eager_only=True)
9967
result = df.rows(named=named)
10068
assert result == expected
10169

10270

103-
@pytest.mark.parametrize("df_raw", [df_pandas_na, df_polars_na])
104-
def test_rows_with_nulls_unnamed(df_raw: Any) -> None:
71+
def test_rows_with_nulls_unnamed(constructor_eager: ConstructorEager) -> None:
10572
# GIVEN
106-
df = nw.from_native(df_raw, eager_only=True)
73+
df = nw.from_native(constructor_eager(data_na), eager_only=True)
10774

10875
# WHEN
10976
result = list(df.iter_rows(named=False))
@@ -119,10 +86,9 @@ def test_rows_with_nulls_unnamed(df_raw: Any) -> None:
11986
assert value_in_result == value
12087

12188

122-
@pytest.mark.parametrize("df_raw", [df_pandas_na, df_polars_na])
123-
def test_rows_with_nulls_named(df_raw: Any) -> None:
89+
def test_rows_with_nulls_named(constructor_eager: ConstructorEager) -> None:
12490
# GIVEN
125-
df = nw.from_native(df_raw, eager_only=True)
91+
df = nw.from_native(constructor_eager(data_na), eager_only=True)
12692

12793
# WHEN
12894
result = list(df.iter_rows(named=True))

tests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
else:
2020
from typing_extensions import TypeAlias # pragma: no cover
2121

22-
Constructor: TypeAlias = Callable[[dict[str, Any]], IntoFrame]
23-
ConstructorEager: TypeAlias = Callable[[dict[str, Any]], IntoDataFrame]
22+
Constructor: TypeAlias = Callable[[Any], IntoFrame]
23+
ConstructorEager: TypeAlias = Callable[[Any], IntoDataFrame]
2424

2525

2626
def zip_strict(left: Sequence[Any], right: Sequence[Any]) -> Iterator[Any]:

0 commit comments

Comments
 (0)