Skip to content

Commit

Permalink
ok future annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Oct 17, 2024
1 parent df97056 commit 4952021
Show file tree
Hide file tree
Showing 101 changed files with 275 additions and 39 deletions.
2 changes: 2 additions & 0 deletions narwhals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from narwhals import dependencies
from narwhals import selectors
from narwhals import stable
Expand Down
2 changes: 2 additions & 0 deletions narwhals/stable/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from narwhals.stable import v1

__all__ = ["v1"]
2 changes: 2 additions & 0 deletions narwhals/stable/v1/_dtypes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from narwhals.dtypes import Array
from narwhals.dtypes import Boolean
from narwhals.dtypes import Categorical
Expand Down
2 changes: 2 additions & 0 deletions narwhals/stable/v1/dtypes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 11 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand All @@ -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]


Expand Down
2 changes: 2 additions & 0 deletions tests/dependencies/is_pandas_dataframe_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pandas as pd
import polars as pl

Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/abs_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/all_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import polars as pl
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/any_all_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/any_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/arg_true_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/binary_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/clip_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/count_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/cum_sum_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/diff_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pyarrow as pa
import pytest

Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/double_selected_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/double_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/fill_null_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/filter_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/gather_every_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_duplicated_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_first_distinct_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_in_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_last_distinct_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_null_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/is_unique_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/len_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/max_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/mean_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/min_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/mode_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import polars as pl
import pytest

Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/n_unique_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/null_count_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/over_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from contextlib import nullcontext as does_not_raise

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/pipe_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/sample_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/shift_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pyarrow as pa

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/sort_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/std_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/str/contains_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pandas as pd
import polars as pl
import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/str/head_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/str/len_chars_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/str/tail_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/sum_horizontal_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Any

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/tail_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals as nw
Expand Down
19 changes: 8 additions & 11 deletions tests/expr_and_series/unary_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import narwhals.stable.v1 as nw
from tests.utils import Constructor
from tests.utils import ConstructorEager
Expand All @@ -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],
Expand Down
2 changes: 2 additions & 0 deletions tests/expr_and_series/unique_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
2 changes: 2 additions & 0 deletions tests/frame/add_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/frame/array_dunder_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numpy as np
import pandas as pd
import polars as pl
Expand Down
2 changes: 2 additions & 0 deletions tests/frame/arrow_c_stream_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import polars as pl
import pyarrow as pa
import pyarrow.compute as pc
Expand Down
2 changes: 2 additions & 0 deletions tests/frame/clone_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

import narwhals.stable.v1 as nw
Expand Down
Loading

0 comments on commit 4952021

Please sign in to comment.