Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
ci-py309-min-optional-deps,
ci-py311-transformers,
ci-py313-latest-deps,
ci-py313-latest-optional-deps
ci-py313-latest-optional-deps,
ci-py313-polars-without-pyarrow
]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2,409 changes: 2,397 additions & 12 deletions pixi.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ pyarrow = "==15.0.2"
polars = "==0.20.15"
plotly = "*"

[tool.pixi.feature.polars-without-pyarrow.dependencies]
polars = "*"
plotly = "*"

[tool.pixi.feature.py309.dependencies]
python = "~=3.9.0"

Expand Down Expand Up @@ -211,6 +215,7 @@ ci-py311-transformers = ["py311", "transformers", "test"]
ci-py312-latest-deps = ["py312", "test"]
ci-py312-latest-optional-deps = ["py312", "optional", "test"]
ci-py313-latest-deps = ["py313", "test"]
ci-py313-polars-without-pyarrow = ["py313", "test", "polars-without-pyarrow"]
ci-py313-latest-optional-deps = ["py313", "optional", "test"]

[tool.black]
Expand Down
3 changes: 3 additions & 0 deletions skrub/_dataframe/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import skrub
from skrub import selectors as s
from skrub._dataframe import _common as ns
from skrub.conftest import polars_installed_without_pyarrow


def test_not_implemented():
Expand Down Expand Up @@ -103,6 +104,7 @@ def test_to_numpy(df_module, example_data_dict):
assert_array_equal(array[2:], np.asarray(example_data_dict["str-col"])[2:])


@polars_installed_without_pyarrow
def test_to_pandas(df_module, pd_module):
with pytest.raises(TypeError):
ns.to_pandas(np.arange(3))
Expand Down Expand Up @@ -725,6 +727,7 @@ def test_mean(df_module):
)


@polars_installed_without_pyarrow
def test_corr(df_module):
df = df_module.example_dataframe

Expand Down
2 changes: 2 additions & 0 deletions skrub/_reporting/tests/test_patch_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import pytest

from skrub import patch_display, unpatch_display
from skrub.conftest import polars_installed_without_pyarrow


@pytest.mark.parametrize("repeat_patch", [1, 2])
@pytest.mark.parametrize("repeat_unpatch", [1, 2])
@polars_installed_without_pyarrow
def test_patch_display(df_module, repeat_patch, repeat_unpatch, capsys):
df = df_module.make_dataframe(
dict(
Expand Down
6 changes: 6 additions & 0 deletions skrub/_reporting/tests/test_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from skrub import _dataframe as sbd
from skrub._reporting import _sample_table
from skrub._reporting._summarize import summarize_dataframe
from skrub.conftest import polars_installed_without_pyarrow


@pytest.mark.parametrize("order_by", [None, "date.utc", "value"])
@pytest.mark.parametrize("with_plots", [False, True])
@pytest.mark.parametrize("with_associations", [False, True])
@polars_installed_without_pyarrow
def test_summarize(
monkeypatch, df_module, air_quality, order_by, with_plots, with_associations
):
Expand Down Expand Up @@ -114,6 +116,7 @@ def test_high_cardinality_column(pd_module):
assert "10 most frequent" in summary["columns"][0]["value_counts_plot"]


@polars_installed_without_pyarrow
def test_all_null(df_module):
df = df_module.make_dataframe(
{
Expand Down Expand Up @@ -142,6 +145,7 @@ def make_summary(df_size, **summarize_kwargs):
return make_summary


@polars_installed_without_pyarrow
def test_small_df(small_df_summary):
summary = small_df_summary(11)
thead, first_slice, ellipsis, last_slice = summary["sample_table"]["parts"]
Expand Down Expand Up @@ -256,6 +260,7 @@ def test_duplicate_columns(pd_module):
assert cols[1]["mean"] == 3.5


@polars_installed_without_pyarrow
def test_high_cardinality_columns(df_module):
df = df_module.make_dataframe(
{
Expand All @@ -269,6 +274,7 @@ def test_high_cardinality_columns(df_module):
assert cols[1]["is_high_cardinality"]


@polars_installed_without_pyarrow
def test_bool_column_mean(df_module):
df = df_module.make_dataframe({"a": [True, False, True, True, False, True]})
summary = summarize_dataframe(df)
Expand Down
13 changes: 13 additions & 0 deletions skrub/_reporting/tests/test_table_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from skrub import TableReport, ToDatetime, datasets
from skrub import _dataframe as sbd
from skrub._reporting._sample_table import make_table
from skrub.conftest import polars_installed_without_pyarrow


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


@polars_installed_without_pyarrow
def test_report(air_quality):
col_filt = {
"first_2": {
Expand Down Expand Up @@ -64,11 +66,13 @@ def test_report(air_quality):
assert len(all_report_ids) == len(set(all_report_ids))


@polars_installed_without_pyarrow
def test_few_columns(df_module, check_polars_numpy2):
report = TableReport(df_module.example_dataframe)
assert "First 10 columns" not in report.html()


@polars_installed_without_pyarrow
def test_few_rows(df_module, check_polars_numpy2):
df = sbd.slice(df_module.example_dataframe, 2)
TableReport(df).html()
Expand All @@ -84,13 +88,15 @@ def test_open(pd_module, browser_mock):
assert b"the title" in browser_mock.content


@polars_installed_without_pyarrow
def test_non_hashable_values(df_module):
# non-regression test for #1066
df = df_module.make_dataframe(dict(a=[[1, 2, 3], None, [4]]))
html = TableReport(df).html()
assert "[1, 2, 3]" in html


@polars_installed_without_pyarrow
def test_nat(df_module):
# non-regression for:
# https://github.com/skrub-data/skrub/issues/1111
Expand All @@ -103,6 +109,7 @@ def test_nat(df_module):
TableReport(df).html()


@polars_installed_without_pyarrow
def test_bool_column_mean(df_module):
df = df_module.make_dataframe({"a": [True, False, True, True, False, True]})
html = TableReport(df).html()
Expand All @@ -116,6 +123,7 @@ def test_duplicate_columns(pd_module):
TableReport(df).html()


@polars_installed_without_pyarrow
def test_infinite_values(df_module):
# Non-regression for https://github.com/skrub-data/skrub/issues/1134
# (histogram plot failing with infinite values)
Expand All @@ -129,6 +137,7 @@ def test_infinite_values(df_module):
TableReport(df).html()


@polars_installed_without_pyarrow
def test_duration(df_module):
df = df_module.make_dataframe(
{"a": [datetime.timedelta(days=2), datetime.timedelta(days=3)]}
Expand Down Expand Up @@ -187,6 +196,7 @@ def test_write_html_with_not_utf8_encoding(tmp_path, pd_module):
assert "</html>" not in saved_content


@polars_installed_without_pyarrow
def test_verbosity_parameter(df_module, capsys):
df = df_module.make_dataframe(
dict(
Expand All @@ -209,6 +219,7 @@ def test_verbosity_parameter(df_module, capsys):
assert capsys.readouterr().err != ""


@polars_installed_without_pyarrow
def test_write_to_stderr(df_module, capsys):
df = df_module.make_dataframe(
dict(
Expand All @@ -229,6 +240,7 @@ def test_write_to_stderr(df_module, capsys):
assert re.search(pattern, captured.err)


@polars_installed_without_pyarrow
def test_max_plot_columns_parameter(df_module):
df = df_module.make_dataframe(
{f"col_{i}": [i + j for j in range(3)] for i in range(10)}
Expand Down Expand Up @@ -288,6 +300,7 @@ def test_error_input_type():
TableReport(df)


@polars_installed_without_pyarrow
def test_single_column_report(df_module):
# Check that single column report works
single_col = df_module.example_column
Expand Down
15 changes: 15 additions & 0 deletions skrub/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ def _example_data_dict():
except ImportError:
_POLARS_INSTALLED = False

if _POLARS_INSTALLED:
try:
import pyarrow # noqa: F401

_polars_installed_without_pyarrow = False
except ImportError:
_polars_installed_without_pyarrow = True
else:
_polars_installed_without_pyarrow = False

polars_installed_without_pyarrow = pytest.mark.skipif(
_polars_installed_without_pyarrow=False,
reason="When polars is installed, requires pyarrow to be installed too",
)


def _pl_from_dict(data):
import polars as pl
Expand Down
2 changes: 2 additions & 0 deletions skrub/tests/test_check_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from skrub import _dataframe as sbd
from skrub._check_input import CheckInputDataFrame
from skrub.conftest import polars_installed_without_pyarrow


def test_good_input(df_module):
Expand Down Expand Up @@ -38,6 +39,7 @@ def test_input_is_an_array():
check.fit_transform(np.ones((2,)))


@polars_installed_without_pyarrow
def test_wrong_dataframe_library_in_transform():
pl = pytest.importorskip("polars")
df = pl.DataFrame({"a": [0, 1], "b": [10, 20]})
Expand Down
3 changes: 3 additions & 0 deletions skrub/tests/test_column_associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

from skrub import _dataframe as sbd
from skrub import column_associations
from skrub.conftest import polars_installed_without_pyarrow


@polars_installed_without_pyarrow
def test_column_associations(df_module):
x = (np.ones((7, 3)) * np.arange(3)).ravel()
y = 2 - 3 * x
Expand All @@ -26,6 +28,7 @@ def test_column_associations(df_module):
)


@polars_installed_without_pyarrow
def test_infinite(df_module):
# non-regression test for https://github.com/skrub-data/skrub/issues/1133
# (column associations would raise an exception on low-cardinality float
Expand Down
3 changes: 3 additions & 0 deletions skrub/tests/test_fuzzy_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from skrub import ToDatetime, _join_utils, fuzzy_join
from skrub import selectors as s
from skrub._dataframe import _common as ns
from skrub.conftest import polars_installed_without_pyarrow


@pytest.mark.parametrize(
Expand Down Expand Up @@ -237,6 +238,7 @@ def test_numerical_column(df_module):
assert ns.shape(fj_num3) == (2, n_cols)


@polars_installed_without_pyarrow
def test_datetime_column(df_module):
"""
Testing that ``fuzzy_join`` works with datetime columns.
Expand Down Expand Up @@ -292,6 +294,7 @@ def to_dt(lst):
assert ns.shape(fj_time3) == (2, n_cols)


@polars_installed_without_pyarrow
def test_mixed_joins(df_module):
"""
Test fuzzy joining on mixed and multiple column types.
Expand Down
2 changes: 2 additions & 0 deletions skrub/tests/test_join_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from skrub import _dataframe as sbd
from skrub import _join_utils
from skrub.conftest import polars_installed_without_pyarrow


@pytest.mark.parametrize(
Expand Down Expand Up @@ -173,6 +174,7 @@ def test_left_join_wrong_right_type(df_module, left):
)


@polars_installed_without_pyarrow
def test_left_join_types_not_equal(df_module, left):
try:
import polars as pl
Expand Down
5 changes: 5 additions & 0 deletions skrub/tests/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
_get_time_zone,
to_datetime,
)
from skrub.conftest import polars_installed_without_pyarrow

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

Expand Down Expand Up @@ -44,6 +45,7 @@ def datetime_col(df_module):
return sbd.col(df_module.example_dataframe, "datetime-col")


@polars_installed_without_pyarrow
@pytest.mark.parametrize(
"format",
[
Expand Down Expand Up @@ -85,6 +87,7 @@ def test_datetime_to_datetime(datetime_col):
assert encoder.format_ is None


@polars_installed_without_pyarrow
def test_rejected_columns(df_module):
with pytest.raises(ValueError, match=".*does not contain strings"):
ToDatetime().fit_transform(sbd.col(df_module.example_dataframe, "float-col"))
Expand All @@ -96,6 +99,7 @@ def test_rejected_columns(df_module):
)


@polars_installed_without_pyarrow
def test_transform_failures(datetime_col, df_module):
encoder = ToDatetime().fit(strftime(datetime_col, ISO))
test_col = df_module.make_column(
Expand All @@ -106,6 +110,7 @@ def test_transform_failures(datetime_col, df_module):
assert sbd.to_list(sbd.fill_nulls(strftime(transformed, ISO), "????")) == expected


@polars_installed_without_pyarrow
def test_mixed_offsets(df_module):
s = df_module.make_column(
"when", ["2020-01-02T08:00:01+02:00", "2020-01-02T08:00:01+04:00"]
Expand Down
2 changes: 2 additions & 0 deletions skrub/tests/test_to_float32.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from skrub._to_categorical import ToCategorical
from skrub._to_datetime import ToDatetime
from skrub._to_float32 import ToFloat32
from skrub.conftest import polars_installed_without_pyarrow


def is_float32(df_module, column):
Expand All @@ -30,6 +31,7 @@ def test_to_float_32(values, df_module):
assert is_float32(df_module, out)


@polars_installed_without_pyarrow
def test_rejected_columns(df_module):
columns = [
df_module.make_column("c", ["1", "2", "hello"]),
Expand Down
2 changes: 2 additions & 0 deletions skrub/tests/test_to_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from skrub._apply_to_cols import RejectColumn
from skrub._to_datetime import ToDatetime
from skrub._to_str import ToStr
from skrub.conftest import polars_installed_without_pyarrow


def test_to_str(df_module):
Expand All @@ -26,6 +27,7 @@ def test_to_str(df_module):
df_module.assert_column_equal(sbd.is_null(out), sbd.is_null(expected))


@polars_installed_without_pyarrow
def test_rejected_columns(df_module):
columns = [
ToDatetime().fit_transform(df_module.make_column("", ["2020-02-02"])),
Expand Down
Loading