diff --git a/narwhals/__init__.py b/narwhals/__init__.py index 21964da15..aeba3ef5e 100644 --- a/narwhals/__init__.py +++ b/narwhals/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from narwhals import dependencies from narwhals import selectors from narwhals import stable diff --git a/narwhals/stable/__init__.py b/narwhals/stable/__init__.py index 572034fe7..60bc872a5 100644 --- a/narwhals/stable/__init__.py +++ b/narwhals/stable/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from narwhals.stable import v1 __all__ = ["v1"] diff --git a/narwhals/stable/v1/_dtypes.py b/narwhals/stable/v1/_dtypes.py index 84c9adc90..459441d66 100644 --- a/narwhals/stable/v1/_dtypes.py +++ b/narwhals/stable/v1/_dtypes.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from narwhals.dtypes import Array from narwhals.dtypes import Boolean from narwhals.dtypes import Categorical diff --git a/narwhals/stable/v1/dtypes.py b/narwhals/stable/v1/dtypes.py index 21bd1c5ed..37c3af0e8 100644 --- a/narwhals/stable/v1/dtypes.py +++ b/narwhals/stable/v1/dtypes.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from narwhals.stable.v1._dtypes import Array from narwhals.stable.v1._dtypes import Boolean from narwhals.stable.v1._dtypes import Categorical diff --git a/tests/conftest.py b/tests/conftest.py index c313a9275..d9fcd7d23 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -48,47 +48,47 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> Any: # pragma: no item.add_marker(skip_slow) -def pandas_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: +def pandas_constructor(obj: dict[str, Any]) -> IntoDataFrame: return pd.DataFrame(obj) # type: ignore[no-any-return] -def pandas_nullable_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: +def pandas_nullable_constructor(obj: dict[str, Any]) -> IntoDataFrame: return pd.DataFrame(obj).convert_dtypes(dtype_backend="numpy_nullable") # type: ignore[no-any-return] -def pandas_pyarrow_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: +def pandas_pyarrow_constructor(obj: dict[str, Any]) -> IntoDataFrame: return pd.DataFrame(obj).convert_dtypes(dtype_backend="pyarrow") # type: ignore[no-any-return] -def modin_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: # pragma: no cover +def modin_constructor(obj: dict[str, Any]) -> IntoDataFrame: # pragma: no cover mpd = get_modin() return mpd.DataFrame(pd.DataFrame(obj)).convert_dtypes(dtype_backend="pyarrow") # type: ignore[no-any-return] -def cudf_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: # pragma: no cover +def cudf_constructor(obj: dict[str, Any]) -> IntoDataFrame: # pragma: no cover cudf = get_cudf() return cudf.DataFrame(obj) # type: ignore[no-any-return] -def polars_eager_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: +def polars_eager_constructor(obj: dict[str, Any]) -> IntoDataFrame: return pl.DataFrame(obj) -def polars_lazy_constructor(obj: dict[str, list[Any]]) -> pl.LazyFrame: +def polars_lazy_constructor(obj: dict[str, Any]) -> pl.LazyFrame: return pl.LazyFrame(obj) -def dask_lazy_p1_constructor(obj: dict[str, list[Any]]) -> IntoFrame: # pragma: no cover +def dask_lazy_p1_constructor(obj: dict[str, Any]) -> IntoFrame: # pragma: no cover dd = get_dask_dataframe() return dd.from_dict(obj, npartitions=1) # type: ignore[no-any-return] -def dask_lazy_p2_constructor(obj: dict[str, list[Any]]) -> IntoFrame: # pragma: no cover +def dask_lazy_p2_constructor(obj: dict[str, Any]) -> IntoFrame: # pragma: no cover dd = get_dask_dataframe() return dd.from_dict(obj, npartitions=2) # type: ignore[no-any-return] -def pyarrow_table_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: +def pyarrow_table_constructor(obj: dict[str, Any]) -> IntoDataFrame: return pa.table(obj) # type: ignore[no-any-return] @@ -115,7 +115,7 @@ def pyarrow_table_constructor(obj: dict[str, list[Any]]) -> IntoDataFrame: @pytest.fixture(params=eager_constructors) def constructor_eager( request: pytest.FixtureRequest, -) -> Callable[[dict[str, list[Any]]], IntoDataFrame]: +) -> Callable[[dict[str, Any]], IntoDataFrame]: return request.param # type: ignore[no-any-return] diff --git a/tests/dependencies/is_pandas_dataframe_test.py b/tests/dependencies/is_pandas_dataframe_test.py index a8ffaa739..96b874952 100644 --- a/tests/dependencies/is_pandas_dataframe_test.py +++ b/tests/dependencies/is_pandas_dataframe_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import polars as pl diff --git a/tests/expr_and_series/abs_test.py b/tests/expr_and_series/abs_test.py index c883d7161..c324a9cfd 100644 --- a/tests/expr_and_series/abs_test.py +++ b/tests/expr_and_series/abs_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/all_horizontal_test.py b/tests/expr_and_series/all_horizontal_test.py index 6f72a2657..beeaecca7 100644 --- a/tests/expr_and_series/all_horizontal_test.py +++ b/tests/expr_and_series/all_horizontal_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import polars as pl diff --git a/tests/expr_and_series/any_all_test.py b/tests/expr_and_series/any_all_test.py index 73294c708..2406cdcff 100644 --- a/tests/expr_and_series/any_all_test.py +++ b/tests/expr_and_series/any_all_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/any_horizontal_test.py b/tests/expr_and_series/any_horizontal_test.py index cd360bf66..d98cd34d6 100644 --- a/tests/expr_and_series/any_horizontal_test.py +++ b/tests/expr_and_series/any_horizontal_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pytest diff --git a/tests/expr_and_series/arg_true_test.py b/tests/expr_and_series/arg_true_test.py index 1f71e2c42..ba6b5d68d 100644 --- a/tests/expr_and_series/arg_true_test.py +++ b/tests/expr_and_series/arg_true_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/binary_test.py b/tests/expr_and_series/binary_test.py index 1ce76d9d2..6826cda37 100644 --- a/tests/expr_and_series/binary_test.py +++ b/tests/expr_and_series/binary_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/expr_and_series/clip_test.py b/tests/expr_and_series/clip_test.py index 2406f289f..14496fc49 100644 --- a/tests/expr_and_series/clip_test.py +++ b/tests/expr_and_series/clip_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/count_test.py b/tests/expr_and_series/count_test.py index ec90e1fc1..603a6daf8 100644 --- a/tests/expr_and_series/count_test.py +++ b/tests/expr_and_series/count_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/cum_sum_test.py b/tests/expr_and_series/cum_sum_test.py index a490b890e..e94bd168c 100644 --- a/tests/expr_and_series/cum_sum_test.py +++ b/tests/expr_and_series/cum_sum_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/diff_test.py b/tests/expr_and_series/diff_test.py index ada3147ed..c62b68d40 100644 --- a/tests/expr_and_series/diff_test.py +++ b/tests/expr_and_series/diff_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pyarrow as pa import pytest diff --git a/tests/expr_and_series/double_selected_test.py b/tests/expr_and_series/double_selected_test.py index 88826fb40..001e1f848 100644 --- a/tests/expr_and_series/double_selected_test.py +++ b/tests/expr_and_series/double_selected_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/expr_and_series/double_test.py b/tests/expr_and_series/double_test.py index 8f19e0202..66af086db 100644 --- a/tests/expr_and_series/double_test.py +++ b/tests/expr_and_series/double_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/expr_and_series/fill_null_test.py b/tests/expr_and_series/fill_null_test.py index 9fa7afaf9..a6315ae59 100644 --- a/tests/expr_and_series/fill_null_test.py +++ b/tests/expr_and_series/fill_null_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/filter_test.py b/tests/expr_and_series/filter_test.py index dff987ecb..afddff244 100644 --- a/tests/expr_and_series/filter_test.py +++ b/tests/expr_and_series/filter_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/gather_every_test.py b/tests/expr_and_series/gather_every_test.py index e6f68be1d..2a2ce154b 100644 --- a/tests/expr_and_series/gather_every_test.py +++ b/tests/expr_and_series/gather_every_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/is_duplicated_test.py b/tests/expr_and_series/is_duplicated_test.py index d0c5ae3dc..d5c934a04 100644 --- a/tests/expr_and_series/is_duplicated_test.py +++ b/tests/expr_and_series/is_duplicated_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/is_first_distinct_test.py b/tests/expr_and_series/is_first_distinct_test.py index 4f22d02f9..c4ad865e3 100644 --- a/tests/expr_and_series/is_first_distinct_test.py +++ b/tests/expr_and_series/is_first_distinct_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/is_in_test.py b/tests/expr_and_series/is_in_test.py index 29d3cf56b..6a568053a 100644 --- a/tests/expr_and_series/is_in_test.py +++ b/tests/expr_and_series/is_in_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/is_last_distinct_test.py b/tests/expr_and_series/is_last_distinct_test.py index e63c161b3..efad08dcb 100644 --- a/tests/expr_and_series/is_last_distinct_test.py +++ b/tests/expr_and_series/is_last_distinct_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/is_null_test.py b/tests/expr_and_series/is_null_test.py index a3d5d2bae..edc0e8953 100644 --- a/tests/expr_and_series/is_null_test.py +++ b/tests/expr_and_series/is_null_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/is_unique_test.py b/tests/expr_and_series/is_unique_test.py index 8d46db92d..39d6fc071 100644 --- a/tests/expr_and_series/is_unique_test.py +++ b/tests/expr_and_series/is_unique_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/len_test.py b/tests/expr_and_series/len_test.py index 535c7dc92..8d582ce1c 100644 --- a/tests/expr_and_series/len_test.py +++ b/tests/expr_and_series/len_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/max_horizontal_test.py b/tests/expr_and_series/max_horizontal_test.py index 711ce4e0d..8da95e317 100644 --- a/tests/expr_and_series/max_horizontal_test.py +++ b/tests/expr_and_series/max_horizontal_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pytest diff --git a/tests/expr_and_series/mean_horizontal_test.py b/tests/expr_and_series/mean_horizontal_test.py index ce9ac8fe0..eb78a868e 100644 --- a/tests/expr_and_series/mean_horizontal_test.py +++ b/tests/expr_and_series/mean_horizontal_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pytest diff --git a/tests/expr_and_series/min_horizontal_test.py b/tests/expr_and_series/min_horizontal_test.py index a837fcad2..eaad0528f 100644 --- a/tests/expr_and_series/min_horizontal_test.py +++ b/tests/expr_and_series/min_horizontal_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pytest diff --git a/tests/expr_and_series/mode_test.py b/tests/expr_and_series/mode_test.py index 820e05ad8..2e752ebb9 100644 --- a/tests/expr_and_series/mode_test.py +++ b/tests/expr_and_series/mode_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import polars as pl import pytest diff --git a/tests/expr_and_series/n_unique_test.py b/tests/expr_and_series/n_unique_test.py index c4199eec1..d54e815cc 100644 --- a/tests/expr_and_series/n_unique_test.py +++ b/tests/expr_and_series/n_unique_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/null_count_test.py b/tests/expr_and_series/null_count_test.py index 93d467cb3..28aa66f38 100644 --- a/tests/expr_and_series/null_count_test.py +++ b/tests/expr_and_series/null_count_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/over_test.py b/tests/expr_and_series/over_test.py index 2abc9a699..4f89c29e5 100644 --- a/tests/expr_and_series/over_test.py +++ b/tests/expr_and_series/over_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from contextlib import nullcontext as does_not_raise import pytest diff --git a/tests/expr_and_series/pipe_test.py b/tests/expr_and_series/pipe_test.py index 84b6006d7..812422f7f 100644 --- a/tests/expr_and_series/pipe_test.py +++ b/tests/expr_and_series/pipe_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/sample_test.py b/tests/expr_and_series/sample_test.py index eb6d853ec..c228ca0bd 100644 --- a/tests/expr_and_series/sample_test.py +++ b/tests/expr_and_series/sample_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/shift_test.py b/tests/expr_and_series/shift_test.py index a665ff768..388b8e6ab 100644 --- a/tests/expr_and_series/shift_test.py +++ b/tests/expr_and_series/shift_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pyarrow as pa import narwhals.stable.v1 as nw diff --git a/tests/expr_and_series/sort_test.py b/tests/expr_and_series/sort_test.py index 2ea8cd145..3721c2599 100644 --- a/tests/expr_and_series/sort_test.py +++ b/tests/expr_and_series/sort_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pytest diff --git a/tests/expr_and_series/std_test.py b/tests/expr_and_series/std_test.py index 09779c109..9ed57c571 100644 --- a/tests/expr_and_series/std_test.py +++ b/tests/expr_and_series/std_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/str/contains_test.py b/tests/expr_and_series/str/contains_test.py index 139b71eb8..2c2e0cb9f 100644 --- a/tests/expr_and_series/str/contains_test.py +++ b/tests/expr_and_series/str/contains_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import polars as pl import pytest diff --git a/tests/expr_and_series/str/head_test.py b/tests/expr_and_series/str/head_test.py index 8da64553e..00406e9d4 100644 --- a/tests/expr_and_series/str/head_test.py +++ b/tests/expr_and_series/str/head_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/str/len_chars_test.py b/tests/expr_and_series/str/len_chars_test.py index 80a791c61..f95efd1a2 100644 --- a/tests/expr_and_series/str/len_chars_test.py +++ b/tests/expr_and_series/str/len_chars_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/str/tail_test.py b/tests/expr_and_series/str/tail_test.py index 260ab745c..aa0821075 100644 --- a/tests/expr_and_series/str/tail_test.py +++ b/tests/expr_and_series/str/tail_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager diff --git a/tests/expr_and_series/sum_horizontal_test.py b/tests/expr_and_series/sum_horizontal_test.py index e9e1e4a3c..91d0d3bb9 100644 --- a/tests/expr_and_series/sum_horizontal_test.py +++ b/tests/expr_and_series/sum_horizontal_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pytest diff --git a/tests/expr_and_series/tail_test.py b/tests/expr_and_series/tail_test.py index 73acb6848..8a7ae8f5b 100644 --- a/tests/expr_and_series/tail_test.py +++ b/tests/expr_and_series/tail_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals as nw diff --git a/tests/expr_and_series/unary_test.py b/tests/expr_and_series/unary_test.py index c1e1d007b..71a00f8f3 100644 --- a/tests/expr_and_series/unary_test.py +++ b/tests/expr_and_series/unary_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import ConstructorEager @@ -6,17 +8,12 @@ def test_unary(constructor: Constructor) -> None: data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]} - result = ( - nw.from_native(constructor(data)) - .with_columns( - a_mean=nw.col("a").mean(), - a_sum=nw.col("a").sum(), - b_nunique=nw.col("b").n_unique(), - z_min=nw.col("z").min(), - z_max=nw.col("z").max(), - ) - .unique(["a_mean", "a_sum", "b_nunique", "z_min", "z_max"]) - .select(["a_mean", "a_sum", "b_nunique", "z_min", "z_max"]) + result = nw.from_native(constructor(data)).select( + a_mean=nw.col("a").mean(), + a_sum=nw.col("a").sum(), + b_nunique=nw.col("b").n_unique(), + z_min=nw.col("z").min(), + z_max=nw.col("z").max(), ) expected = { "a_mean": [2], diff --git a/tests/expr_and_series/unique_test.py b/tests/expr_and_series/unique_test.py index 5048d3250..db0478e80 100644 --- a/tests/expr_and_series/unique_test.py +++ b/tests/expr_and_series/unique_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/frame/add_test.py b/tests/frame/add_test.py index c95fbae97..69133c2e8 100644 --- a/tests/frame/add_test.py +++ b/tests/frame/add_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/frame/array_dunder_test.py b/tests/frame/array_dunder_test.py index ad3085f56..90db2b621 100644 --- a/tests/frame/array_dunder_test.py +++ b/tests/frame/array_dunder_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import numpy as np import pandas as pd import polars as pl diff --git a/tests/frame/arrow_c_stream_test.py b/tests/frame/arrow_c_stream_test.py index cb856adf9..66525f1b9 100644 --- a/tests/frame/arrow_c_stream_test.py +++ b/tests/frame/arrow_c_stream_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import polars as pl import pyarrow as pa import pyarrow.compute as pc diff --git a/tests/frame/clone_test.py b/tests/frame/clone_test.py index e94183e2e..c115d0899 100644 --- a/tests/frame/clone_test.py +++ b/tests/frame/clone_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/frame/columns_test.py b/tests/frame/columns_test.py index 90a9c922d..3a18fb591 100644 --- a/tests/frame/columns_test.py +++ b/tests/frame/columns_test.py @@ -1,7 +1,13 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pytest import narwhals.stable.v1 as nw -from tests.utils import Constructor + +if TYPE_CHECKING: + from tests.utils import Constructor @pytest.mark.filterwarnings("ignore:Determining|Resolving.*") diff --git a/tests/frame/concat_test.py b/tests/frame/concat_test.py index 926f3f988..ebf4bcb05 100644 --- a/tests/frame/concat_test.py +++ b/tests/frame/concat_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/frame/double_test.py b/tests/frame/double_test.py index 6840145ec..1c46bf3f7 100644 --- a/tests/frame/double_test.py +++ b/tests/frame/double_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/frame/filter_test.py b/tests/frame/filter_test.py index 9c9b1b6fd..3f10fba8a 100644 --- a/tests/frame/filter_test.py +++ b/tests/frame/filter_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from contextlib import nullcontext as does_not_raise import pytest diff --git a/tests/frame/gather_every_test.py b/tests/frame/gather_every_test.py index 40e18a30b..347132c14 100644 --- a/tests/frame/gather_every_test.py +++ b/tests/frame/gather_every_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/frame/get_column_test.py b/tests/frame/get_column_test.py index ff4ebc506..b0a2a7ca5 100644 --- a/tests/frame/get_column_test.py +++ b/tests/frame/get_column_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import pytest diff --git a/tests/frame/interchange_native_namespace_test.py b/tests/frame/interchange_native_namespace_test.py index 8a67d07b8..084f6ea05 100644 --- a/tests/frame/interchange_native_namespace_test.py +++ b/tests/frame/interchange_native_namespace_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import duckdb import polars as pl import pytest diff --git a/tests/frame/interchange_schema_test.py b/tests/frame/interchange_schema_test.py index afec06831..33f2e0044 100644 --- a/tests/frame/interchange_schema_test.py +++ b/tests/frame/interchange_schema_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import date from datetime import datetime from datetime import timedelta diff --git a/tests/frame/interchange_to_arrow_test.py b/tests/frame/interchange_to_arrow_test.py index 7308607ea..d1ddd2a53 100644 --- a/tests/frame/interchange_to_arrow_test.py +++ b/tests/frame/interchange_to_arrow_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import duckdb import polars as pl import pyarrow as pa diff --git a/tests/frame/interchange_to_pandas_test.py b/tests/frame/interchange_to_pandas_test.py index f56575fa3..3cb722b1c 100644 --- a/tests/frame/interchange_to_pandas_test.py +++ b/tests/frame/interchange_to_pandas_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import duckdb import pandas as pd import pytest diff --git a/tests/frame/invalid_test.py b/tests/frame/invalid_test.py index 2fdf53949..834e192b7 100644 --- a/tests/frame/invalid_test.py +++ b/tests/frame/invalid_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import numpy as np import pandas as pd import polars as pl diff --git a/tests/frame/lazy_test.py b/tests/frame/lazy_test.py index 8f1566e69..df27a4cc9 100644 --- a/tests/frame/lazy_test.py +++ b/tests/frame/lazy_test.py @@ -1,6 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals as nw import narwhals.stable.v1 as nw_v1 -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager def test_lazy(constructor_eager: ConstructorEager) -> None: diff --git a/tests/frame/len_test.py b/tests/frame/len_test.py index cd082ef2e..b22f0c67d 100644 --- a/tests/frame/len_test.py +++ b/tests/frame/len_test.py @@ -1,6 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals.stable.v1 as nw -from tests.utils import ConstructorEager +if TYPE_CHECKING: + from tests.utils import ConstructorEager data = { "a": [1.0, 2.0, None, 4.0], "b": [None, 3.0, None, 5.0], diff --git a/tests/frame/pipe_test.py b/tests/frame/pipe_test.py index b7b57e0a1..506d4a317 100644 --- a/tests/frame/pipe_test.py +++ b/tests/frame/pipe_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/frame/reindex_test.py b/tests/frame/reindex_test.py index e21b31a8e..431e7b002 100644 --- a/tests/frame/reindex_test.py +++ b/tests/frame/reindex_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any import pandas as pd diff --git a/tests/frame/rename_test.py b/tests/frame/rename_test.py index 79cf3f243..d51e86f83 100644 --- a/tests/frame/rename_test.py +++ b/tests/frame/rename_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/frame/row_test.py b/tests/frame/row_test.py index d977a81f1..82af94146 100644 --- a/tests/frame/row_test.py +++ b/tests/frame/row_test.py @@ -1,9 +1,14 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING from typing import Any import pytest import narwhals.stable.v1 as nw -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager def test_row_column(request: Any, constructor_eager: ConstructorEager) -> None: diff --git a/tests/frame/sample_test.py b/tests/frame/sample_test.py index 88d5969c3..ff3591fdd 100644 --- a/tests/frame/sample_test.py +++ b/tests/frame/sample_test.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals.stable.v1 as nw -from tests.utils import Constructor + +if TYPE_CHECKING: + from tests.utils import Constructor def test_sample_n(constructor_eager: Constructor) -> None: diff --git a/tests/frame/schema_test.py b/tests/frame/schema_test.py index 97c3722a7..65da7bf00 100644 --- a/tests/frame/schema_test.py +++ b/tests/frame/schema_test.py @@ -1,7 +1,10 @@ +from __future__ import annotations + from datetime import date from datetime import datetime from datetime import timedelta from datetime import timezone +from typing import TYPE_CHECKING from typing import Any import duckdb @@ -11,8 +14,11 @@ import narwhals.stable.v1 as nw from narwhals.utils import parse_version -from tests.utils import Constructor -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import Constructor + from tests.utils import ConstructorEager + data = { "a": [datetime(2020, 1, 1)], diff --git a/tests/frame/select_test.py b/tests/frame/select_test.py index 8c01be407..df7821a5b 100644 --- a/tests/frame/select_test.py +++ b/tests/frame/select_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import pytest diff --git a/tests/frame/shape_test.py b/tests/frame/shape_test.py index 6930214f7..6cbee058d 100644 --- a/tests/frame/shape_test.py +++ b/tests/frame/shape_test.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals.stable.v1 as nw -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager def test_shape(constructor_eager: ConstructorEager) -> None: diff --git a/tests/frame/to_dict_test.py b/tests/frame/to_dict_test.py index b76003bd1..537b68f31 100644 --- a/tests/frame/to_dict_test.py +++ b/tests/frame/to_dict_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/frame/to_native_test.py b/tests/frame/to_native_test.py index c6de99a17..fb90caf10 100644 --- a/tests/frame/to_native_test.py +++ b/tests/frame/to_native_test.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals.stable.v1 as nw -from tests.utils import Constructor + +if TYPE_CHECKING: + from tests.utils import Constructor def test_to_native(constructor: Constructor) -> None: diff --git a/tests/frame/with_columns_sequence_test.py b/tests/frame/with_columns_sequence_test.py index 49db7820b..5249f0106 100644 --- a/tests/frame/with_columns_sequence_test.py +++ b/tests/frame/with_columns_sequence_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import numpy as np import pytest diff --git a/tests/frame/with_columns_test.py b/tests/frame/with_columns_test.py index 8c949cc53..722df5c01 100644 --- a/tests/frame/with_columns_test.py +++ b/tests/frame/with_columns_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import numpy as np import pandas as pd import pyarrow as pa diff --git a/tests/frame/with_row_index_test.py b/tests/frame/with_row_index_test.py index 8f802de0a..a4307acc3 100644 --- a/tests/frame/with_row_index_test.py +++ b/tests/frame/with_row_index_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/from_dict_test.py b/tests/from_dict_test.py index 4583b03e5..9797713d9 100644 --- a/tests/from_dict_test.py +++ b/tests/from_dict_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals as nw diff --git a/tests/from_pycapsule_test.py b/tests/from_pycapsule_test.py index 7ab8f1fe8..496138dd2 100644 --- a/tests/from_pycapsule_test.py +++ b/tests/from_pycapsule_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys import pandas as pd diff --git a/tests/new_series_test.py b/tests/new_series_test.py index 37e5d2633..f5dda284d 100644 --- a/tests/new_series_test.py +++ b/tests/new_series_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import pytest diff --git a/tests/no_imports_test.py b/tests/no_imports_test.py index b30545380..a6fe26e31 100644 --- a/tests/no_imports_test.py +++ b/tests/no_imports_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys import pandas as pd diff --git a/tests/series_only/alias_rename_test.py b/tests/series_only/alias_rename_test.py index 4fa8a9993..021992735 100644 --- a/tests/series_only/alias_rename_test.py +++ b/tests/series_only/alias_rename_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals as nw from tests.utils import Constructor from tests.utils import compare_dicts diff --git a/tests/series_only/array_dunder_test.py b/tests/series_only/array_dunder_test.py index 0d95e2db3..3c30ef894 100644 --- a/tests/series_only/array_dunder_test.py +++ b/tests/series_only/array_dunder_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import numpy as np import pandas as pd import pyarrow as pa diff --git a/tests/series_only/arrow_c_stream_test.py b/tests/series_only/arrow_c_stream_test.py index 9d2ebc8d0..3417bb9a5 100644 --- a/tests/series_only/arrow_c_stream_test.py +++ b/tests/series_only/arrow_c_stream_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import polars as pl import pyarrow as pa import pyarrow.compute as pc diff --git a/tests/series_only/cast_test.py b/tests/series_only/cast_test.py index 672cbebc2..55752149b 100644 --- a/tests/series_only/cast_test.py +++ b/tests/series_only/cast_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import date from datetime import datetime diff --git a/tests/series_only/is_empty_test.py b/tests/series_only/is_empty_test.py index 390fa7f4f..bd3aa61ed 100644 --- a/tests/series_only/is_empty_test.py +++ b/tests/series_only/is_empty_test.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals.stable.v1 as nw -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager def test_is_empty(constructor_eager: ConstructorEager) -> None: diff --git a/tests/series_only/is_ordered_categorical_test.py b/tests/series_only/is_ordered_categorical_test.py index 10251e362..58aa9616f 100644 --- a/tests/series_only/is_ordered_categorical_test.py +++ b/tests/series_only/is_ordered_categorical_test.py @@ -1,3 +1,7 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pandas as pd import polars as pl import pyarrow as pa @@ -5,7 +9,9 @@ import narwhals.stable.v1 as nw from narwhals.utils import parse_version -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager def test_is_ordered_categorical() -> None: diff --git a/tests/series_only/shape_test.py b/tests/series_only/shape_test.py index d3e276bb2..1ab88eca3 100644 --- a/tests/series_only/shape_test.py +++ b/tests/series_only/shape_test.py @@ -1,5 +1,11 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import narwhals.stable.v1 as nw -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager def test_shape(constructor_eager: ConstructorEager) -> None: diff --git a/tests/series_only/slice_test.py b/tests/series_only/slice_test.py index eba24fdbd..0744c1b77 100644 --- a/tests/series_only/slice_test.py +++ b/tests/series_only/slice_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import ConstructorEager from tests.utils import compare_dicts diff --git a/tests/series_only/to_dummy_test.py b/tests/series_only/to_dummy_test.py index 938b8d04e..52b51242e 100644 --- a/tests/series_only/to_dummy_test.py +++ b/tests/series_only/to_dummy_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/series_only/to_frame_test.py b/tests/series_only/to_frame_test.py index 065da1414..77be9a4be 100644 --- a/tests/series_only/to_frame_test.py +++ b/tests/series_only/to_frame_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import narwhals.stable.v1 as nw from tests.utils import ConstructorEager from tests.utils import compare_dicts diff --git a/tests/series_only/to_list_test.py b/tests/series_only/to_list_test.py index 0f91b9879..ebea07cff 100644 --- a/tests/series_only/to_list_test.py +++ b/tests/series_only/to_list_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest import narwhals.stable.v1 as nw diff --git a/tests/stable_api_test.py b/tests/stable_api_test.py index 7a67f5723..a076b0218 100644 --- a/tests/stable_api_test.py +++ b/tests/stable_api_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from datetime import timedelta from typing import Any diff --git a/tests/system_info_test.py b/tests/system_info_test.py index 30bb0c400..75a2b190f 100644 --- a/tests/system_info_test.py +++ b/tests/system_info_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import warnings from typing import Any diff --git a/tests/translate/from_native_test.py b/tests/translate/from_native_test.py index 8ac33b620..2d5ecd642 100644 --- a/tests/translate/from_native_test.py +++ b/tests/translate/from_native_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from contextlib import nullcontext as does_not_raise from typing import Any diff --git a/tests/translate/get_native_namespace_test.py b/tests/translate/get_native_namespace_test.py index 60b80a1d9..f02c4c8da 100644 --- a/tests/translate/get_native_namespace_test.py +++ b/tests/translate/get_native_namespace_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import polars as pl import pyarrow as pa diff --git a/tests/translate/to_native_test.py b/tests/translate/to_native_test.py index 90ec11ab1..3d116a459 100644 --- a/tests/translate/to_native_test.py +++ b/tests/translate/to_native_test.py @@ -1,10 +1,15 @@ +from __future__ import annotations + from contextlib import nullcontext as does_not_raise +from typing import TYPE_CHECKING from typing import Any import pytest import narwhals.stable.v1 as nw -from tests.utils import ConstructorEager + +if TYPE_CHECKING: + from tests.utils import ConstructorEager @pytest.mark.parametrize( diff --git a/tests/utils.py b/tests/utils.py index e1d0365c1..8ac877396 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -19,8 +19,8 @@ else: from typing_extensions import TypeAlias # pragma: no cover -Constructor: TypeAlias = Callable[[dict[str, list[Any]]], IntoFrame] -ConstructorEager: TypeAlias = Callable[[dict[str, list[Any]]], IntoDataFrame] +Constructor: TypeAlias = Callable[[dict[str, Any]], IntoFrame] +ConstructorEager: TypeAlias = Callable[[dict[str, Any]], IntoDataFrame] def zip_strict(left: Sequence[Any], right: Sequence[Any]) -> Iterator[Any]: @@ -30,7 +30,7 @@ def zip_strict(left: Sequence[Any], right: Sequence[Any]) -> Iterator[Any]: return zip(left, right) -def compare_dicts(result: Any, expected: dict[str, list[Any]]) -> None: +def compare_dicts(result: Any, expected: dict[str, Any]) -> None: if hasattr(result, "collect"): result = result.collect() if hasattr(result, "columns"): diff --git a/tests/utils_test.py b/tests/utils_test.py index cea458bc9..30805b15d 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pandas as pd import polars as pl import pytest diff --git a/utils/check_api_reference.py b/utils/check_api_reference.py index e3aa0fb91..75acfe5cd 100644 --- a/utils/check_api_reference.py +++ b/utils/check_api_reference.py @@ -53,7 +53,7 @@ for i in content.splitlines() if i.startswith(" - ") ] -if missing := set(top_level_functions).difference(documented): +if missing := set(top_level_functions).difference(documented).difference({"annotations"}): print("top-level functions: not documented") # noqa: T201 print(missing) # noqa: T201 ret = 1