Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up making Python tests more deterministic #17272

Open
wants to merge 2 commits into
base: branch-24.12
Choose a base branch
from
Open
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
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,8 @@ repos:
types: [python]
- id: no-unseeded-default-rng
name: no-unseeded-default-rng
description: 'Enforce that no non-seeded default_rng is used and default_rng is used instead of np.random.seed'
entry: |
# Check for usage of default_rng without seeding
default_rng\(\)|
# Check for usage of np.random.seed
np.random.seed\(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this without the parenthesis to forbid usage of np.random.seed in favor of the newer default_rng API?

description: 'Enforce that np.random.default_rng is seeded'
entry: default_rng\(\)
language: pygrep
types: [python]
- id: cmake-format
Expand Down
11 changes: 3 additions & 8 deletions python/cudf/cudf/tests/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ def parquet_file(request, tmp_path_factory, pdf):
return fname


@pytest.fixture(scope="module")
def rdg_seed():
return int(os.environ.get("TEST_CUDF_RDG_SEED", "42"))


def make_pdf(nrows, ncolumns=1, nvalids=0, dtype=np.int64):
test_pdf = pd.DataFrame(
[list(range(ncolumns * i, ncolumns * (i + 1))) for i in range(nrows)],
Expand Down Expand Up @@ -431,7 +426,7 @@ def num_row_groups(rows, group_size):
assert a == b


def test_parquet_read_filtered(tmpdir, rdg_seed):
def test_parquet_read_filtered(tmpdir):
# Generate data
fname = tmpdir.join("filtered.parquet")
dg.generate(
Expand All @@ -455,13 +450,13 @@ def test_parquet_read_filtered(tmpdir, rdg_seed):
dg.ColumnParameters(
40,
0.2,
lambda: np.random.default_rng(seed=None).integers(
lambda: np.random.default_rng(seed=0).integers(
0, 100, size=40
),
True,
),
],
seed=rdg_seed,
seed=42,
),
format={"name": "parquet", "row_group_size": 64},
)
Expand Down
17 changes: 1 addition & 16 deletions python/dask_cudf/dask_cudf/tests/test_reductions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Copyright (c) 2021-2024, NVIDIA CORPORATION.

import numpy as np
import pandas as pd
import pytest

import dask
Expand All @@ -10,20 +8,7 @@
import cudf

import dask_cudf


def _make_random_frame(nelem, npartitions=2):
rng = np.random.default_rng(seed=0)
df = pd.DataFrame(
{
"x": rng.integers(0, 5, size=nelem),
"y": rng.normal(loc=1.0, scale=1.0, size=nelem),
}
)
gdf = cudf.DataFrame.from_pandas(df)
dgf = dask_cudf.from_cudf(gdf, npartitions=npartitions)
return df, dgf

from dask_cudf.tests.utils import _make_random_frame

_reducers = ["sum", "count", "mean", "var", "std", "min", "max"]

Expand Down
2 changes: 1 addition & 1 deletion python/dask_cudf/dask_cudf/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def _make_random_frame(nelem, npartitions=2, include_na=False):
rng = np.random.default_rng(seed=None)
rng = np.random.default_rng(seed=0)
df = pd.DataFrame(
{"x": rng.random(size=nelem), "y": rng.random(size=nelem)}
)
Expand Down
Loading