Skip to content

Commit

Permalink
Move partition limit constant to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed May 14, 2024
1 parent 2792215 commit c21c7df
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 0 additions & 2 deletions py-polars/polars/testing/_constants.py

This file was deleted.

6 changes: 6 additions & 0 deletions py-polars/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
)


@pytest.fixture()
def partition_limit() -> int:
"""The limit at which Polars will start partitioning in debug builds."""
return 15


@pytest.fixture()
def df() -> pl.DataFrame:
df = pl.DataFrame(
Expand Down
7 changes: 3 additions & 4 deletions py-polars/tests/unit/operations/test_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import polars as pl
import polars.selectors as cs
from polars.testing import assert_frame_equal, assert_series_equal
from polars.testing._constants import PARTITION_LIMIT

if TYPE_CHECKING:
from polars.type_aliases import PolarsDataType
Expand Down Expand Up @@ -770,10 +769,10 @@ def test_group_by_partitioned_ending_cast(monkeypatch: Any) -> None:
assert_frame_equal(out, expected)


def test_group_by_series_partitioned() -> None:
def test_group_by_series_partitioned(partition_limit: int) -> None:
# test 15354
df = pl.DataFrame([0, 0] * PARTITION_LIMIT)
groups = pl.Series([0, 1] * PARTITION_LIMIT)
df = pl.DataFrame([0, 0] * partition_limit)
groups = pl.Series([0, 1] * partition_limit)
df.group_by(groups).agg(pl.all().is_not_null().sum())


Expand Down
15 changes: 9 additions & 6 deletions py-polars/tests/unit/streaming/test_streaming_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import polars as pl
from polars.testing import assert_frame_equal
from polars.testing._constants import PARTITION_LIMIT

if TYPE_CHECKING:
from pathlib import Path
Expand Down Expand Up @@ -483,16 +482,20 @@ def test_streaming_groupby_binary_15116() -> None:
}


def test_streaming_group_by_convert_15380() -> None:
def test_streaming_group_by_convert_15380(partition_limit: int) -> None:
assert (
pl.DataFrame({"a": [1] * PARTITION_LIMIT}).group_by(b="a").len()["len"].item()
== PARTITION_LIMIT
pl.DataFrame({"a": [1] * partition_limit}).group_by(b="a").len()["len"].item()
== partition_limit
)


@pytest.mark.parametrize("streaming", [True, False])
@pytest.mark.parametrize("n_rows", [PARTITION_LIMIT - 1, PARTITION_LIMIT + 3])
def test_streaming_group_by_boolean_mean_15610(n_rows: int, streaming: bool) -> None:
@pytest.mark.parametrize("n_rows_limit_offset", [-1, +3])
def test_streaming_group_by_boolean_mean_15610(
n_rows_limit_offset: int, streaming: bool, partition_limit: int
) -> None:
n_rows = partition_limit + n_rows_limit_offset

# Also test non-streaming because it sometimes dispatched to streaming agg.
expect = pl.DataFrame({"a": [False, True], "c": [0.0, 0.5]})

Expand Down

0 comments on commit c21c7df

Please sign in to comment.