Skip to content

Commit 02ab3cb

Browse files
committed
test: cover v1, v2
1 parent d939ef7 commit 02ab3cb

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

tests/v1_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Test assorted functions which we overwrite in stable.v1
22
from __future__ import annotations
33

4+
from collections import deque
45
from contextlib import nullcontext as does_not_raise
56
from datetime import datetime, timedelta
67
from typing import TYPE_CHECKING, Any, Callable, cast
@@ -37,6 +38,7 @@
3738
Constructor,
3839
ConstructorEager,
3940
assert_equal_data,
41+
assert_equal_series,
4042
)
4143

4244
if TYPE_CHECKING:
@@ -1049,3 +1051,30 @@ def test_series_from_numpy(
10491051
if dtype:
10501052
assert result.dtype == dtype
10511053
assert_equal_data(result.to_frame(), {name: expected})
1054+
1055+
1056+
@pytest.mark.parametrize(
1057+
("dtype", "expected"),
1058+
[
1059+
(None, [5, 2, 0, 1]),
1060+
(nw_v1.Int64, [5, 2, 0, 1]),
1061+
(nw_v1.String, ("a", "b", "c")),
1062+
(nw_v1.Float64, [5.0, 2.0, 0.0, 1.0]),
1063+
(
1064+
nw_v1.Datetime(),
1065+
deque([datetime(2005, 1, 1, 10), datetime(2002, 1, 1, 10, 43)]),
1066+
),
1067+
],
1068+
ids=str,
1069+
)
1070+
def test_series_from_iterable(
1071+
eager_backend: EagerAllowed, dtype: IntoDType | None, expected: Sequence[Any]
1072+
) -> None:
1073+
data = expected
1074+
name = "abc"
1075+
result = nw_v1.Series.from_iterable(name, data, backend=eager_backend, dtype=dtype)
1076+
assert result._version is Version.V1
1077+
assert isinstance(result, nw_v1.Series)
1078+
if dtype:
1079+
assert result.dtype == dtype
1080+
assert_equal_series(result, expected, name)

tests/v2_test.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
from collections import deque
6+
from datetime import datetime
57
from typing import TYPE_CHECKING, Any
68

79
import numpy as np
@@ -10,12 +12,21 @@
1012

1113
import narwhals.stable.v2 as nw_v2
1214
from narwhals.utils import Version
13-
from tests.utils import PANDAS_VERSION, Constructor, assert_equal_data
15+
from tests.utils import (
16+
PANDAS_VERSION,
17+
Constructor,
18+
assert_equal_data,
19+
assert_equal_series,
20+
)
1421

1522
if TYPE_CHECKING:
23+
from collections.abc import Sequence
24+
1625
from typing_extensions import assert_type
1726

27+
from narwhals._namespace import EagerAllowed
1828
from narwhals.stable.v2.typing import IntoDataFrameT
29+
from narwhals.typing import IntoDType
1930

2031

2132
def test_toplevel() -> None:
@@ -332,3 +343,30 @@ def test_imports() -> None:
332343
from narwhals.stable.v2.dtypes import Enum # noqa: F401
333344
from narwhals.stable.v2.selectors import datetime # noqa: F401
334345
from narwhals.stable.v2.typing import IntoDataFrame # noqa: F401
346+
347+
348+
@pytest.mark.parametrize(
349+
("dtype", "expected"),
350+
[
351+
(None, [5, 2, 0, 1]),
352+
(nw_v2.Int64, [5, 2, 0, 1]),
353+
(nw_v2.String, ("a", "b", "c")),
354+
(nw_v2.Float64, [5.0, 2.0, 0.0, 1.0]),
355+
(
356+
nw_v2.Datetime(),
357+
deque([datetime(2005, 1, 1, 10), datetime(2002, 1, 1, 10, 43)]),
358+
),
359+
],
360+
ids=str,
361+
)
362+
def test_series_from_iterable(
363+
eager_backend: EagerAllowed, dtype: IntoDType | None, expected: Sequence[Any]
364+
) -> None:
365+
data = expected
366+
name = "abc"
367+
result = nw_v2.Series.from_iterable(name, data, backend=eager_backend, dtype=dtype)
368+
assert result._version is Version.V2
369+
assert isinstance(result, nw_v2.Series)
370+
if dtype:
371+
assert result.dtype == dtype
372+
assert_equal_series(result, expected, name)

0 commit comments

Comments
 (0)