Skip to content

Commit 7eed8fc

Browse files
Disable progress bar if total is 0 (#3696)
### Changes Disable progress bar if total is 0 ### Reason for changes To avoid print progress bar if total is 0 ``` Working... ━━━━━━━━━━━━━━━━━━━ 0% 0/0 • 0:00:00 • 0:00:00 ``` ### Tests tests/common/utils/test_progress_tracking.py::test_disable_with_total_0
1 parent 4ee9d00 commit 7eed8fc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/nncf/common/logging/track_progress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def __init__(
213213
)
214214
)
215215

216-
disable = disable or (hasattr(sequence, "__len__") and len(sequence) == 0) # type: ignore[arg-type]
216+
disable = disable or (hasattr(sequence, "__len__") and len(sequence) == 0) or self.total == 0 # type: ignore[arg-type]
217217

218218
progress_cls = Progress if weights is None else WeightedProgress
219219
self.progress = progress_cls(

tests/common/utils/test_progress_tracking.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,10 @@ def test_track_context_manager(n, is_weighted):
8484
for i in range(n):
8585
assert pbar.progress._tasks[pbar.task].completed == (sum(weights[:i]) if is_weighted else i)
8686
pbar.update(advance=1)
87+
88+
89+
def test_disable_with_total_0():
90+
pbar = track(iter(get_sequence(0)), total=0)
91+
assert pbar.progress.disable is True
92+
pbar = track(iter(get_sequence(0)))
93+
assert pbar.progress.disable is False

0 commit comments

Comments
 (0)