Skip to content

MAINT Parameters validation for datasets.make_moons #25971

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

Merged
merged 7 commits into from Mar 27, 2023
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
8 changes: 8 additions & 0 deletions sklearn/datasets/_samples_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ def make_circles(
return X, y


@validate_params(
{
"n_samples": [Interval(Integral, 1, None, closed="left"), tuple],
"shuffle": ["boolean"],
"noise": [Interval(Real, 0, None, closed="left"), None],
"random_state": ["random_state"],
}
)
def make_moons(n_samples=100, *, shuffle=True, noise=None, random_state=None):
"""Make two interleaving half circles.

Expand Down
6 changes: 0 additions & 6 deletions sklearn/datasets/tests/test_samples_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,6 @@ def test_make_moons_unbalanced():
assert X.shape == (12, 2), "X shape mismatch"
assert y.shape == (12,), "y shape mismatch"

with pytest.raises(
ValueError,
match=r"`n_samples` can be either an int " r"or a two-element tuple.",
):
make_moons(n_samples=[1, 2, 3])

with pytest.raises(
ValueError,
match=r"`n_samples` can be either an int " r"or a two-element tuple.",
Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def _check_function_param_validation(
"sklearn.datasets.make_classification",
"sklearn.datasets.make_friedman1",
"sklearn.datasets.make_low_rank_matrix",
"sklearn.datasets.make_moons",
"sklearn.datasets.make_multilabel_classification",
"sklearn.datasets.make_regression",
"sklearn.datasets.make_sparse_coded_signal",
Expand Down