Skip to content

Commit 2051a38

Browse files
committed
recover some column tests
1 parent 123672f commit 2051a38

File tree

11 files changed

+32
-134
lines changed

11 files changed

+32
-134
lines changed

dataframe_api_compat/polars_standard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def convert_to_standard_compliant_dataframe(
198198

199199
def convert_to_standard_compliant_column(
200200
ser: pl.Series, api_version: str | None = None
201-
) -> PolarsColumn[Any]:
201+
) -> PolarsColumn[Any]: # pragma: no cover (todo: is this even needed?)
202202
return PolarsColumn(
203203
ser, dtype=ser.dtype, id_=None, api_version=api_version or LATEST_API_VERSION
204204
)

tests/column/column_test.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
import polars as pl
77

88
from dataframe_api_compat import pandas_standard
9-
from dataframe_api_compat import polars_standard
9+
from tests.utils import integer_dataframe_1
1010

1111

1212
def test_column_column() -> None:
13-
result_pl = (
14-
polars_standard.convert_to_standard_compliant_dataframe(
15-
pl.DataFrame({"a": [1, 2, 3]}), "2023.08-beta"
16-
)
17-
.get_column_by_name("a")
18-
.column
19-
)
13+
namespace = integer_dataframe_1("polars-lazy").__dataframe_namespace__()
14+
ser = namespace.column_from_sequence([1, 2, 3], name="a", dtype=namespace.Int64())
15+
result_pl = ser.column
2016
result_pl = cast(pl.Series, result_pl)
2117
pd.testing.assert_series_equal(result_pl.to_pandas(), pd.Series([1, 2, 3], name="a"))
2218
result_pd = (

tests/column/get_value_test.py

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

3-
from typing import TYPE_CHECKING
4-
53
from tests.utils import integer_series_1
64

7-
if TYPE_CHECKING:
8-
import pytest
9-
105

11-
def test_get_value(library: str, request: pytest.FixtureRequest) -> None:
12-
result = integer_series_1(library, request).get_value(0)
6+
def test_get_value(library: str) -> None:
7+
result = integer_series_1(library).get_value(0)
138
assert result == 1

tests/column/len_test.py

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

3-
from typing import TYPE_CHECKING
4-
53
from tests.utils import integer_series_1
64

7-
if TYPE_CHECKING:
8-
import pytest
9-
105

11-
def test_column_len(library: str, request: pytest.FixtureRequest) -> None:
12-
result = len(integer_series_1(library, request))
6+
def test_column_len(library: str) -> None:
7+
result = len(integer_series_1(library))
138
assert result == 3

tests/column/slice_rows_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from tests.utils import convert_series_to_pandas_numpy
99
from tests.utils import integer_dataframe_3
10+
from tests.utils import interchange_to_pandas
1011

1112

1213
@pytest.mark.parametrize(
@@ -24,15 +25,14 @@ def test_column_slice_rows(
2425
stop: int | None,
2526
step: int | None,
2627
expected: pd.Series[Any],
27-
request: pytest.FixtureRequest,
2828
) -> None:
29-
if library == "polars-lazy":
30-
request.node.add_marker(pytest.mark.xfail())
31-
ser = integer_dataframe_3(library).get_column_by_name("a")
32-
namespace = ser.__column_namespace__()
29+
namespace = integer_dataframe_3(library).__dataframe_namespace__()
30+
ser = namespace.column_from_sequence(
31+
[1, 2, 3, 4, 5, 6, 7], name="a", dtype=namespace.Int64()
32+
)
3333
result = ser.slice_rows(start, stop, step)
34-
result_pd = pd.api.interchange.from_dataframe(
35-
namespace.dataframe_from_dict({"result": (result).rename("result")}).dataframe
34+
result_pd = interchange_to_pandas(
35+
namespace.dataframe_from_dict({"result": (result).rename("result")}), library
3636
)["result"]
3737
result_pd = convert_series_to_pandas_numpy(result_pd)
3838
pd.testing.assert_series_equal(result_pd, expected)

tests/column/statistics_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def test_std(library: str, request: pytest.FixtureRequest) -> None:
1919
assert abs(result - 1.7320508075688772) < 1e-8
2020

2121

22-
def test_column_max(library: str, request: pytest.FixtureRequest) -> None:
23-
result = integer_series_1(library, request).max()
22+
def test_column_max(library: str) -> None:
23+
result = integer_series_1(library).max()
2424
assert result == 3

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
def pytest_generate_tests(metafunc: Any) -> None:
77
if "library" in metafunc.fixturenames:
88
metafunc.parametrize(
9-
"library", ["pandas-numpy", "pandas-nullable", "polars", "polars-lazy"]
9+
"library", ["pandas-numpy", "pandas-nullable", "polars-lazy"]
1010
)

tests/namespace/column_from_1d_array_test.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
],
2424
)
2525
def test_column_from_1d_array(
26-
library: str, request: pytest.FixtureRequest, namespace_dtype: str, pandas_dtype: str
26+
library: str, namespace_dtype: str, pandas_dtype: str
2727
) -> None:
28-
if library == "polars-lazy":
29-
request.node.add_marker(pytest.mark.xfail())
3028
ser = integer_dataframe_1(library).get_column_by_name("a")
3129
namespace = ser.__column_namespace__()
3230
arr = np.array([1, 2, 3])
@@ -49,10 +47,8 @@ def test_column_from_1d_array(
4947
],
5048
)
5149
def test_column_from_1d_array_string(
52-
library: str, request: pytest.FixtureRequest, namespace_dtype: str, pandas_dtype: str
50+
library: str, namespace_dtype: str, pandas_dtype: str
5351
) -> None:
54-
if library == "polars-lazy":
55-
request.node.add_marker(pytest.mark.xfail())
5652
ser = integer_dataframe_1(library).get_column_by_name("a")
5753
namespace = ser.__column_namespace__()
5854
arr = np.array(["a", "b", "c"])
@@ -70,8 +66,7 @@ def test_column_from_1d_array_string(
7066

7167

7268
def test_column_from_array_invalid(library: str) -> None:
73-
ser = integer_dataframe_1(library).get_column_by_name("a")
74-
namespace = ser.__column_namespace__()
69+
namespace = integer_dataframe_1(library).__dataframe_namespace__()
7570
arr = np.array(["a", "b", "c"])
7671
with pytest.raises(ValueError):
7772
namespace.column_from_1d_array(

tests/namespace/column_from_sequence_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import pandas as pd
66
import pytest
77

8-
from tests.utils import convert_series_to_pandas_numpy
98
from tests.utils import integer_dataframe_1
9+
from tests.utils import interchange_to_pandas
1010

1111

1212
@pytest.mark.parametrize(
@@ -47,6 +47,5 @@ def test_column_from_sequence(
4747
)
4848
}
4949
)
50-
result_pd = pd.api.interchange.from_dataframe(result.dataframe)["result"]
51-
result_pd = convert_series_to_pandas_numpy(result_pd)
50+
result_pd = interchange_to_pandas(result, library)["result"]
5251
pd.testing.assert_series_equal(result_pd, expected)

tests/namespace/dataframe_from_2d_array_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
from tests.utils import interchange_to_pandas
1010

1111

12-
def test_dataframe_from_2d_array(library: str, request: pytest.FixtureRequest) -> None:
13-
if library == "polars-lazy":
14-
request.node.add_marker(pytest.mark.xfail())
12+
def test_dataframe_from_2d_array(library: str) -> None:
1513
df = integer_dataframe_1(library)
1614
namespace = df.__dataframe_namespace__()
1715
arr = np.array([[1, 4], [2, 5], [3, 6]])

0 commit comments

Comments
 (0)