From 2638078f1824625d5b6bb3bba591c5585b73d8e8 Mon Sep 17 00:00:00 2001 From: alexander-beedie Date: Mon, 9 Oct 2023 02:17:07 +0400 Subject: [PATCH] update tests for 'diagonal_relaxed' --- crates/polars-sql/src/context.rs | 2 +- py-polars/polars/functions/eager.py | 16 ++++++++++++---- py-polars/tests/unit/test_errors.py | 20 +++++++++----------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/crates/polars-sql/src/context.rs b/crates/polars-sql/src/context.rs index c2d8f4b6070ba..4ad3039a75b6a 100644 --- a/crates/polars-sql/src/context.rs +++ b/crates/polars-sql/src/context.rs @@ -214,7 +214,7 @@ impl SQLContext { }, // UNION ALL BY NAME // TODO: add recognition for SetQuantifier::DistinctByName - // when "https://github.com/sqlparser-rs/sqlparser-rs/pull/997" is merged + // when "https://github.com/sqlparser-rs/sqlparser-rs/pull/997" is available SetQuantifier::AllByName => concat_lf_diagonal(vec![left, right], opts), // UNION [DISTINCT] BY NAME SetQuantifier::ByName => { diff --git a/py-polars/polars/functions/eager.py b/py-polars/polars/functions/eager.py index 12a99319f394f..95e484efb0b7d 100644 --- a/py-polars/polars/functions/eager.py +++ b/py-polars/polars/functions/eager.py @@ -193,8 +193,11 @@ def concat( elif how == "horizontal": out = wrap_df(plr.concat_df_horizontal(elems)) else: - allowed = get_args(ConcatMethod) - raise ValueError(f"DataFrame `how` must be one of {allowed!r}, got {how!r}") + allowed = ", ".join(repr(m) for m in get_args(ConcatMethod)) + raise ValueError( + f"DataFrame `how` must be one of {{{allowed}}}, got {how!r}" + ) + elif isinstance(first, pl.LazyFrame): if how in ("vertical", "vertical_relaxed"): return wrap_ldf( @@ -215,8 +218,13 @@ def concat( ) ) else: - allowed = tuple(m for m in get_args(ConcatMethod) if m != "horizontal") - raise ValueError(f"LazyFrame `how` must be one of {allowed!r}, got {how!r}") + allowed = ", ".join( + repr(m) for m in get_args(ConcatMethod) if m != "horizontal" + ) + raise ValueError( + f"LazyFrame `how` must be one of {{{allowed}}}, got {how!r}" + ) + elif isinstance(first, pl.Series): if how == "vertical": out = wrap_s(plr.concat_series(elems)) diff --git a/py-polars/tests/unit/test_errors.py b/py-polars/tests/unit/test_errors.py index 4185b2b9b068a..0076d9d859106 100644 --- a/py-polars/tests/unit/test_errors.py +++ b/py-polars/tests/unit/test_errors.py @@ -276,25 +276,23 @@ def test_window_expression_different_group_length() -> None: def test_lazy_concat_err() -> None: - df1 = pl.DataFrame( + df = pl.DataFrame( { "foo": [1, 2], "bar": [6, 7], "ham": ["a", "b"], } ) - df2 = pl.DataFrame( - { - "foo": [3, 4], - "ham": ["c", "d"], - "bar": [8, 9], - } - ) with pytest.raises( ValueError, - match="LazyFrame `how` must be one of ('vertical', 'vertical_relaxed', 'diagonal', 'diagonal_relaxed', 'align'), got 'horizontal'", + match="DataFrame `how` must be one of {'vertical', 'vertical_relaxed', 'diagonal', 'diagonal_relaxed', 'horizontal', 'align'}, got 'sausage'", + ): + pl.concat([df, df], how="sausage") # type: ignore[arg-type] + with pytest.raises( + ValueError, + match="LazyFrame `how` must be one of {'vertical', 'vertical_relaxed', 'diagonal', 'diagonal_relaxed', 'align'}, got 'horizontal'", ): - pl.concat([df1.lazy(), df2.lazy()], how="horizontal").collect() + pl.concat([df.lazy(), df.lazy()], how="horizontal").collect() @pytest.mark.parametrize("how", ["horizontal", "diagonal"]) @@ -302,7 +300,7 @@ def test_series_concat_err(how: ConcatMethod) -> None: s = pl.Series([1, 2, 3]) with pytest.raises( ValueError, - match="Series only allows 'vertical' concat strategy", + match="Series only supports 'vertical' concat strategy", ): pl.concat([s, s], how=how)