-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[Data] Fix bug where Ray Data incorrectly emits progress bar warning #47680
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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,4 +1,6 @@ | ||
import functools | ||
import logging | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from pytest import fixture | ||
|
@@ -39,7 +41,7 @@ def wrapped_close(): | |
bar.close = wrapped_close | ||
|
||
# Test basic usage | ||
pb = ProgressBar("", total, "", enabled=True) | ||
pb = ProgressBar("", total, "unit", enabled=True) | ||
assert pb._bar is not None | ||
patch_close(pb._bar) | ||
for _ in range(total): | ||
|
@@ -50,7 +52,7 @@ def wrapped_close(): | |
assert total_at_close == total | ||
|
||
# Test if update() exceeds the original total, the total will be updated. | ||
pb = ProgressBar("", total, "", enabled=True) | ||
pb = ProgressBar("", total, "unit", enabled=True) | ||
assert pb._bar is not None | ||
patch_close(pb._bar) | ||
new_total = total * 2 | ||
|
@@ -62,7 +64,7 @@ def wrapped_close(): | |
assert total_at_close == new_total | ||
|
||
# Test that if the bar is not complete at close(), the total will be updated. | ||
pb = ProgressBar("", total, "") | ||
pb = ProgressBar("", total, "unit") | ||
assert pb._bar is not None | ||
patch_close(pb._bar) | ||
new_total = total // 2 | ||
|
@@ -74,7 +76,7 @@ def wrapped_close(): | |
assert total_at_close == new_total | ||
|
||
# Test updating the total | ||
pb = ProgressBar("", total, "", enabled=True) | ||
pb = ProgressBar("", total, "unit", enabled=True) | ||
assert pb._bar is not None | ||
patch_close(pb._bar) | ||
new_total = total * 2 | ||
|
@@ -84,3 +86,40 @@ def wrapped_close(): | |
pb.update(total + 1, total) | ||
assert pb._bar.total == total + 1 | ||
pb.close() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name, expected_description, max_line_length, should_emit_warning", | ||
[ | ||
("Op", "Op", 2, False), | ||
("Op->Op", "Op->Op", 5, False), | ||
("Op->Op->Op", "Op->...->Op", 9, True), | ||
("Op->Op->Op", "Op->Op->Op", 10, False), | ||
# Test case for https://github.com/ray-project/ray/issues/47679. | ||
("spam", "spam", 1, False), | ||
], | ||
) | ||
def test_progress_bar_truncates_chained_operators( | ||
name, | ||
expected_description, | ||
max_line_length, | ||
should_emit_warning, | ||
caplog, | ||
propagate_logs, | ||
): | ||
with patch.object(ProgressBar, "MAX_NAME_LENGTH", max_line_length): | ||
pb = ProgressBar(name, None, "unit") | ||
|
||
assert pb.get_description() == expected_description | ||
if should_emit_warning: | ||
assert any( | ||
record.levelno == logging.WARNING | ||
and "Truncating long operator name" in record.message | ||
for record in caplog.records | ||
), caplog.records | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
sys.exit(pytest.main(["-v", __file__])) | ||
Comment on lines
+122
to
+125
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. pytest strikes again... |
Oops, something went wrong.
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.
This test was broken