Skip to content

Commit

Permalink
test(python): Set specific temp dir for OOC tests (#14420)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Feb 11, 2024
1 parent 055dc36 commit 84d5920
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
13 changes: 5 additions & 8 deletions py-polars/tests/unit/streaming/test_streaming.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import os
import tempfile
import time
from datetime import date
from pathlib import Path
Expand Down Expand Up @@ -347,19 +346,17 @@ def test_streaming_csv_headers_but_no_data_13770(tmp_path: Path) -> None:


@pytest.mark.write_disk()
def test_custom_temp_dir(monkeypatch: Any) -> None:
test_temp_dir = "test_temp_dir"
temp_dir = Path(tempfile.gettempdir()) / test_temp_dir

monkeypatch.setenv("POLARS_VERBOSE", "1")
def test_custom_temp_dir(tmp_path: Path, monkeypatch: Any) -> None:
tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")
monkeypatch.setenv("POLARS_TEMP_DIR", str(temp_dir))
monkeypatch.setenv("POLARS_VERBOSE", "1")

s = pl.arange(0, 100_000, eager=True).rename("idx")
df = s.shuffle().to_frame()
df.lazy().sort("idx").collect(streaming=True)

assert os.listdir(temp_dir), f"Temp directory '{temp_dir}' is empty"
assert os.listdir(tmp_path), f"Temp directory '{tmp_path}' is empty"


@pytest.mark.write_disk()
Expand Down
26 changes: 22 additions & 4 deletions py-polars/tests/unit/streaming/test_streaming_group_by.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from __future__ import annotations

from datetime import date
from typing import Any
from typing import TYPE_CHECKING, Any

import numpy as np
import pytest

import polars as pl
from polars.testing import assert_frame_equal

if TYPE_CHECKING:
from pathlib import Path

pytestmark = pytest.mark.xdist_group("streaming")


Expand Down Expand Up @@ -202,9 +205,14 @@ def random_integers() -> pl.Series:

@pytest.mark.write_disk()
def test_streaming_group_by_ooc_q1(
monkeypatch: Any, random_integers: pl.Series
random_integers: pl.Series,
tmp_path: Path,
monkeypatch: Any,
) -> None:
s = random_integers

tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")

result = (
Expand All @@ -228,9 +236,14 @@ def test_streaming_group_by_ooc_q1(

@pytest.mark.write_disk()
def test_streaming_group_by_ooc_q2(
monkeypatch: Any, random_integers: pl.Series
random_integers: pl.Series,
tmp_path: Path,
monkeypatch: Any,
) -> None:
s = random_integers

tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")

result = (
Expand All @@ -255,9 +268,14 @@ def test_streaming_group_by_ooc_q2(

@pytest.mark.write_disk()
def test_streaming_group_by_ooc_q3(
monkeypatch: Any, random_integers: pl.Series
random_integers: pl.Series,
tmp_path: Path,
monkeypatch: Any,
) -> None:
s = random_integers

tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")

result = (
Expand Down
18 changes: 13 additions & 5 deletions py-polars/tests/unit/streaming/test_streaming_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def test_streaming_sort_multiple_columns_logical_types() -> None:

@pytest.mark.write_disk()
@pytest.mark.slow()
def test_ooc_sort(monkeypatch: Any) -> None:
def test_ooc_sort(tmp_path: Path, monkeypatch: Any) -> None:
tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")

s = pl.arange(0, 100_000, eager=True).rename("idx")
Expand All @@ -91,9 +93,11 @@ def test_ooc_sort(monkeypatch: Any) -> None:


@pytest.mark.write_disk()
def test_streaming_sort(monkeypatch: Any, capfd: Any) -> None:
monkeypatch.setenv("POLARS_VERBOSE", "1")
def test_streaming_sort(tmp_path: Path, monkeypatch: Any, capfd: Any) -> None:
tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")
monkeypatch.setenv("POLARS_VERBOSE", "1")
# this creates a lot of duplicate partitions and triggers: #7568
assert (
pl.Series(np.random.randint(0, 100, 100))
Expand All @@ -108,7 +112,9 @@ def test_streaming_sort(monkeypatch: Any, capfd: Any) -> None:


@pytest.mark.write_disk()
def test_out_of_core_sort_9503(monkeypatch: Any) -> None:
def test_out_of_core_sort_9503(tmp_path: Path, monkeypatch: Any) -> None:
tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")
np.random.seed(0)

Expand Down Expand Up @@ -169,8 +175,10 @@ def test_out_of_core_sort_9503(monkeypatch: Any) -> None:
@pytest.mark.write_disk()
@pytest.mark.slow()
def test_streaming_sort_multiple_columns(
str_ints_df: pl.DataFrame, monkeypatch: Any, capfd: Any
str_ints_df: pl.DataFrame, tmp_path: Path, monkeypatch: Any, capfd: Any
) -> None:
tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")
monkeypatch.setenv("POLARS_VERBOSE", "1")
df = str_ints_df
Expand Down
4 changes: 3 additions & 1 deletion py-polars/tests/unit/streaming/test_streaming_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
@pytest.mark.write_disk()
@pytest.mark.slow()
def test_streaming_out_of_core_unique(
io_files_path: Path, monkeypatch: Any, capfd: Any
io_files_path: Path, tmp_path: Path, monkeypatch: Any, capfd: Any
) -> None:
tmp_path.mkdir(exist_ok=True)
monkeypatch.setenv("POLARS_TEMP_DIR", str(tmp_path))
monkeypatch.setenv("POLARS_FORCE_OOC", "1")
monkeypatch.setenv("POLARS_VERBOSE", "1")
monkeypatch.setenv("POLARS_STREAMING_GROUPBY_SPILL_SIZE", "256")
Expand Down

0 comments on commit 84d5920

Please sign in to comment.