Skip to content

Commit a94b040

Browse files
committed
commonize var
1 parent d48434e commit a94b040

12 files changed

Lines changed: 55 additions & 33 deletions

skrub/_dataframe/tests/test_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import skrub
1919
from skrub import selectors as s
2020
from skrub._dataframe import _common as ns
21+
from skrub.conftest import polars_installed_without_pyarrow
2122

2223

2324
def test_not_implemented():
@@ -725,7 +726,7 @@ def test_mean(df_module):
725726
)
726727

727728

728-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
729+
@polars_installed_without_pyarrow
729730
def test_corr(df_module):
730731
df = df_module.example_dataframe
731732

skrub/_reporting/tests/test_patch_display.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import pytest
44

55
from skrub import patch_display, unpatch_display
6+
from skrub.conftest import polars_installed_without_pyarrow
67

78

89
@pytest.mark.parametrize("repeat_patch", [1, 2])
910
@pytest.mark.parametrize("repeat_unpatch", [1, 2])
10-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
11+
@polars_installed_without_pyarrow
1112
def test_patch_display(df_module, repeat_patch, repeat_unpatch, capsys):
1213
df = df_module.make_dataframe(
1314
dict(

skrub/_reporting/tests/test_summarize.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
from skrub import _dataframe as sbd
1010
from skrub._reporting import _sample_table
1111
from skrub._reporting._summarize import summarize_dataframe
12+
from skrub.conftest import polars_installed_without_pyarrow
1213

1314

1415
@pytest.mark.parametrize("order_by", [None, "date.utc", "value"])
1516
@pytest.mark.parametrize("with_plots", [False, True])
1617
@pytest.mark.parametrize("with_associations", [False, True])
17-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
18+
@polars_installed_without_pyarrow
1819
def test_summarize(
1920
monkeypatch, df_module, air_quality, order_by, with_plots, with_associations
2021
):
@@ -115,7 +116,7 @@ def test_high_cardinality_column(pd_module):
115116
assert "10 most frequent" in summary["columns"][0]["value_counts_plot"]
116117

117118

118-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
119+
@polars_installed_without_pyarrow
119120
def test_all_null(df_module):
120121
df = df_module.make_dataframe(
121122
{
@@ -144,7 +145,7 @@ def make_summary(df_size, **summarize_kwargs):
144145
return make_summary
145146

146147

147-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
148+
@polars_installed_without_pyarrow
148149
def test_small_df(small_df_summary):
149150
summary = small_df_summary(11)
150151
thead, first_slice, ellipsis, last_slice = summary["sample_table"]["parts"]
@@ -259,7 +260,7 @@ def test_duplicate_columns(pd_module):
259260
assert cols[1]["mean"] == 3.5
260261

261262

262-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
263+
@polars_installed_without_pyarrow
263264
def test_high_cardinality_columns(df_module):
264265
df = df_module.make_dataframe(
265266
{

skrub/_reporting/tests/test_table_report.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from skrub import TableReport, ToDatetime, datasets
1212
from skrub import _dataframe as sbd
1313
from skrub._reporting._sample_table import make_table
14+
from skrub.conftest import polars_installed_without_pyarrow
1415

1516

1617
def get_report_id(html):
1718
return re.search(r'<skrub-table-report.*?id="report_([a-z0-9]+)"', html).group(1)
1819

1920

20-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
21+
@polars_installed_without_pyarrow
2122
def test_report(air_quality):
2223
col_filt = {
2324
"first_2": {
@@ -65,13 +66,13 @@ def test_report(air_quality):
6566
assert len(all_report_ids) == len(set(all_report_ids))
6667

6768

68-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
69+
@polars_installed_without_pyarrow
6970
def test_few_columns(df_module, check_polars_numpy2):
7071
report = TableReport(df_module.example_dataframe)
7172
assert "First 10 columns" not in report.html()
7273

7374

74-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
75+
@polars_installed_without_pyarrow
7576
def test_few_rows(df_module, check_polars_numpy2):
7677
df = sbd.slice(df_module.example_dataframe, 2)
7778
TableReport(df).html()
@@ -87,15 +88,15 @@ def test_open(pd_module, browser_mock):
8788
assert b"the title" in browser_mock.content
8889

8990

90-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
91+
@polars_installed_without_pyarrow
9192
def test_non_hashable_values(df_module):
9293
# non-regression test for #1066
9394
df = df_module.make_dataframe(dict(a=[[1, 2, 3], None, [4]]))
9495
html = TableReport(df).html()
9596
assert "[1, 2, 3]" in html
9697

9798

98-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
99+
@polars_installed_without_pyarrow
99100
def test_nat(df_module):
100101
# non-regression for:
101102
# https://github.com/skrub-data/skrub/issues/1111
@@ -114,7 +115,7 @@ def test_duplicate_columns(pd_module):
114115
TableReport(df).html()
115116

116117

117-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
118+
@polars_installed_without_pyarrow
118119
def test_infinite_values(df_module):
119120
# Non-regression for https://github.com/skrub-data/skrub/issues/1134
120121
# (histogram plot failing with infinite values)
@@ -128,7 +129,7 @@ def test_infinite_values(df_module):
128129
TableReport(df).html()
129130

130131

131-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
132+
@polars_installed_without_pyarrow
132133
def test_duration(df_module):
133134
df = df_module.make_dataframe(
134135
{"a": [datetime.timedelta(days=2), datetime.timedelta(days=3)]}
@@ -187,7 +188,7 @@ def test_write_html_with_not_utf8_encoding(tmp_path, pd_module):
187188
assert "</html>" not in saved_content
188189

189190

190-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
191+
@polars_installed_without_pyarrow
191192
def test_verbosity_parameter(df_module, capsys):
192193
df = df_module.make_dataframe(
193194
dict(
@@ -210,7 +211,7 @@ def test_verbosity_parameter(df_module, capsys):
210211
assert capsys.readouterr().err != ""
211212

212213

213-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
214+
@polars_installed_without_pyarrow
214215
def test_write_to_stderr(df_module, capsys):
215216
df = df_module.make_dataframe(
216217
dict(
@@ -231,7 +232,7 @@ def test_write_to_stderr(df_module, capsys):
231232
assert re.search(pattern, captured.err)
232233

233234

234-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
235+
@polars_installed_without_pyarrow
235236
def test_max_plot_columns_parameter(df_module):
236237
df = df_module.make_dataframe(
237238
{f"col_{i}": [i + j for j in range(3)] for i in range(10)}
@@ -291,7 +292,7 @@ def test_error_input_type():
291292
TableReport(df)
292293

293294

294-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
295+
@polars_installed_without_pyarrow
295296
def test_single_column_report(df_module):
296297
# Check that single column report works
297298
single_col = df_module.example_column

skrub/conftest.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,22 @@ def _example_data_dict():
9595
except ImportError:
9696
_POLARS_INSTALLED = False
9797

98-
try:
99-
import pyarrow # noqa: F401
98+
if _POLARS_INSTALLED:
99+
try:
100+
import pyarrow # noqa: F401
100101

101-
_PYARROW_INSTALLED = True
102-
except ImportError:
103-
_PYARROW_INSTALLED = False
102+
_polars_installed_without_pyarrow = False
103+
except ImportError:
104+
_polars_installed_without_pyarrow = True
105+
else:
106+
_polars_installed_without_pyarrow = False
107+
108+
polars_installed_without_pyarrow = pytest.mark.skipif(
109+
_polars_installed_without_pyarrow=False,
110+
reason="When polars is installed, requires pyarrow to be installed too",
111+
)
112+
113+
pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
104114

105115

106116
def _pl_from_dict(data):

skrub/tests/test_check_input.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from skrub import _dataframe as sbd
66
from skrub._check_input import CheckInputDataFrame
7+
from skrub.conftest import polars_installed_without_pyarrow
78

89

910
def test_good_input(df_module):
@@ -38,7 +39,7 @@ def test_input_is_an_array():
3839
check.fit_transform(np.ones((2,)))
3940

4041

41-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
42+
@polars_installed_without_pyarrow
4243
def test_wrong_dataframe_library_in_transform():
4344
pl = pytest.importorskip("polars")
4445
df = pl.DataFrame({"a": [0, 1], "b": [10, 20]})

skrub/tests/test_column_associations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
from skrub import _dataframe as sbd
77
from skrub import column_associations
8+
from skrub.conftest import polars_installed_without_pyarrow
89

910

10-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
11+
@polars_installed_without_pyarrow
1112
def test_column_associations(df_module):
1213
x = (np.ones((7, 3)) * np.arange(3)).ravel()
1314
y = 2 - 3 * x
@@ -27,7 +28,7 @@ def test_column_associations(df_module):
2728
)
2829

2930

30-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
31+
@polars_installed_without_pyarrow
3132
def test_infinite(df_module):
3233
# non-regression test for https://github.com/skrub-data/skrub/issues/1133
3334
# (column associations would raise an exception on low-cardinality float

skrub/tests/test_fuzzy_join.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from skrub import ToDatetime, _join_utils, fuzzy_join
99
from skrub import selectors as s
1010
from skrub._dataframe import _common as ns
11+
from skrub.conftest import polars_installed_without_pyarrow
1112

1213

1314
@pytest.mark.parametrize(
@@ -237,7 +238,7 @@ def test_numerical_column(df_module):
237238
assert ns.shape(fj_num3) == (2, n_cols)
238239

239240

240-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
241+
@polars_installed_without_pyarrow
241242
def test_datetime_column(df_module):
242243
"""
243244
Testing that ``fuzzy_join`` works with datetime columns.
@@ -293,7 +294,7 @@ def to_dt(lst):
293294
assert ns.shape(fj_time3) == (2, n_cols)
294295

295296

296-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
297+
@polars_installed_without_pyarrow
297298
def test_mixed_joins(df_module):
298299
"""
299300
Test fuzzy joining on mixed and multiple column types.

skrub/tests/test_join_utils.py

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

77
from skrub import _dataframe as sbd
88
from skrub import _join_utils
9+
from skrub.conftest import polars_installed_without_pyarrow
910

1011

1112
@pytest.mark.parametrize(
@@ -173,6 +174,7 @@ def test_left_join_wrong_right_type(df_module, left):
173174
)
174175

175176

177+
@polars_installed_without_pyarrow
176178
def test_left_join_types_not_equal(df_module, left):
177179
try:
178180
import polars as pl

skrub/tests/test_to_datetime.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
_get_time_zone,
1717
to_datetime,
1818
)
19+
from skrub.conftest import polars_installed_without_pyarrow
1920

2021
ISO = "%Y-%m-%dT%H:%M:%S"
2122

@@ -44,7 +45,7 @@ def datetime_col(df_module):
4445
return sbd.col(df_module.example_dataframe, "datetime-col")
4546

4647

47-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
48+
@polars_installed_without_pyarrow
4849
@pytest.mark.parametrize(
4950
"format",
5051
[
@@ -86,7 +87,7 @@ def test_datetime_to_datetime(datetime_col):
8687
assert encoder.format_ is None
8788

8889

89-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
90+
@polars_installed_without_pyarrow
9091
def test_rejected_columns(df_module):
9192
with pytest.raises(ValueError, match=".*does not contain strings"):
9293
ToDatetime().fit_transform(sbd.col(df_module.example_dataframe, "float-col"))
@@ -98,7 +99,7 @@ def test_rejected_columns(df_module):
9899
)
99100

100101

101-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
102+
@polars_installed_without_pyarrow
102103
def test_transform_failures(datetime_col, df_module):
103104
encoder = ToDatetime().fit(strftime(datetime_col, ISO))
104105
test_col = df_module.make_column(
@@ -109,7 +110,7 @@ def test_transform_failures(datetime_col, df_module):
109110
assert sbd.to_list(sbd.fill_nulls(strftime(transformed, ISO), "????")) == expected
110111

111112

112-
@pytest.mark.skipif(_PYARROW_INSTALLED=False, reason="requires pyarrow to be installed")
113+
@polars_installed_without_pyarrow
113114
def test_mixed_offsets(df_module):
114115
s = df_module.make_column(
115116
"when", ["2020-01-02T08:00:01+02:00", "2020-01-02T08:00:01+04:00"]

0 commit comments

Comments
 (0)