-
-
Notifications
You must be signed in to change notification settings - Fork 271
[MNT] Fix race condition in OpenMLSplit tests during parallel execution #1641 #1694
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
Open
codervinitjangir
wants to merge
9
commits into
openml:main
Choose a base branch
from
codervinitjangir:fix/race-condition-split
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
447aff1
fix: race condition in OpenMLSplitTest when running tests in parallel…
codervinitjangir b29157d
Merge branch 'main' into fix/race-condition-split
codervinitjangir 6d0b51d
Apply maintainer cleanup suggestions
codervinitjangir 981213d
Fix race condition setup by preserving temp dir and restoring eq test
codervinitjangir d962e74
Revert setUp to original main branch state and adapt tearDown
codervinitjangir ebe11c3
Revert setUp to match upstream main, simplify tearDown as requested
codervinitjangir f6bac1f
Merge branch 'main' into fix/race-condition-split
codervinitjangir 758577e
Merge branch 'main' into fix/race-condition-split
codervinitjangir 7f00928
Merge branch 'main' into fix/race-condition-split
PGijsbers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,13 +1,15 @@ | ||||
| # License: BSD 3-Clause | ||||
| from __future__ import annotations | ||||
|
|
||||
| import contextlib | ||||
| import inspect | ||||
| import os | ||||
| import shutil | ||||
| import tempfile | ||||
| from pathlib import Path | ||||
|
|
||||
| import numpy as np | ||||
| import pytest | ||||
|
|
||||
| from openml import OpenMLSplit | ||||
| from openml.testing import TestBase | ||||
|
|
@@ -18,8 +20,11 @@ class OpenMLSplitTest(TestBase): | |||
| # than 5 seconds + rebuilding the test would potentially be costly | ||||
|
|
||||
| def setUp(self): | ||||
| super().setUp() | ||||
| self._temp_dir = tempfile.TemporaryDirectory() | ||||
| __file__ = inspect.getfile(OpenMLSplitTest) | ||||
| self.directory = os.path.dirname(__file__) | ||||
| # This is for dataset | ||||
| source_arff = ( | ||||
| Path(self.directory).parent | ||||
| / "files" | ||||
|
|
@@ -30,23 +35,16 @@ def setUp(self): | |||
| / "1882" | ||||
| / "datasplits.arff" | ||||
| ) | ||||
| # Use a unique temp directory for each test to avoid race conditions | ||||
| # when running tests in parallel (see issue #1641) | ||||
| self._temp_dir = tempfile.TemporaryDirectory() | ||||
| self.arff_filepath = Path(self._temp_dir.name) / "datasplits.arff" | ||||
| shutil.copy(source_arff, self.arff_filepath) | ||||
| self.pd_filename = self.arff_filepath.with_suffix(".pkl.py3") | ||||
|
|
||||
| def tearDown(self): | ||||
| # Clean up the entire temp directory | ||||
| try: | ||||
| self._temp_dir.cleanup() | ||||
| except (OSError, FileNotFoundError): | ||||
| pass | ||||
| self._temp_dir.cleanup() | ||||
|
|
||||
| def test_eq(self): | ||||
| split = OpenMLSplit._from_arff_file(self.arff_filepath) | ||||
| assert split == split | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry about that, I think this should be kept, since it tests eq |
||||
| assert split == split # noqa: PLR0124 | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line can be removed
Suggested change
|
||||
|
|
||||
| split2 = OpenMLSplit._from_arff_file(self.arff_filepath) | ||||
| split2.name = "a" | ||||
|
|
@@ -88,17 +86,7 @@ def test_get_split(self): | |||
| train_split, test_split = split.get(fold=5, repeat=2) | ||||
| assert train_split.shape[0] == 808 | ||||
| assert test_split.shape[0] == 90 | ||||
| self.assertRaisesRegex( | ||||
| ValueError, | ||||
| "Repeat 10 not known", | ||||
| split.get, | ||||
| 10, | ||||
| 2, | ||||
| ) | ||||
| self.assertRaisesRegex( | ||||
| ValueError, | ||||
| "Fold 10 not known", | ||||
| split.get, | ||||
| 2, | ||||
| 10, | ||||
| ) | ||||
| with pytest.raises(ValueError, match="Repeat 10 not known"): | ||||
| split.get(10, 2) | ||||
| with pytest.raises(ValueError, match="Fold 10 not known"): | ||||
| split.get(2, 10) | ||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't change anything here, keep it as it was
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1694 (comment) is still unresolved