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

Expose progress bar class control #1110

Merged
merged 15 commits into from
May 20, 2024
31 changes: 27 additions & 4 deletions src/hdmf/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@
doc="Display a progress bar with iteration rate and estimated completion time.",
default=False,
),
dict(
name="progress_bar_class",
type=None, # Would prefer callable, but docval can't handle
doc="The progress bar class to use. Defaults to tqdm.tqdm if the TQDM package is installed.",
default=None,
),
dict(
name="progress_bar_options",
type=None,
type=dict,
doc="Dictionary of keyword arguments to be passed directly to tqdm.",
default=None,
),
Expand All @@ -199,8 +205,23 @@
HDF5 recommends chunk size in the range of 2 to 16 MB for optimal cloud performance.
https://youtu.be/rcS5vt-mKok?t=621
"""
buffer_gb, buffer_shape, chunk_mb, chunk_shape, self.display_progress, progress_bar_options = getargs(
"buffer_gb", "buffer_shape", "chunk_mb", "chunk_shape", "display_progress", "progress_bar_options", kwargs
(
buffer_gb,
buffer_shape,
chunk_mb,
chunk_shape,
self.display_progress,
progress_bar_class,
progress_bar_options,
) = getargs(
"buffer_gb",
"buffer_shape",
"chunk_mb",
"chunk_shape",
"display_progress",
"progress_bar_class",
"progress_bar_options",
kwargs,
)
self.progress_bar_options = progress_bar_options or dict()

Expand Down Expand Up @@ -277,11 +298,13 @@
try:
from tqdm import tqdm

progress_bar_class = progress_bar_class or tqdm

Check warning on line 301 in src/hdmf/data_utils.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/data_utils.py#L301

Added line #L301 was not covered by tests

if "total" in self.progress_bar_options:
warn("Option 'total' in 'progress_bar_options' is not allowed to be over-written! Ignoring.")
self.progress_bar_options.pop("total")

self.progress_bar = tqdm(total=self.num_buffers, **self.progress_bar_options)
self.progress_bar = progress_bar_class(total=self.num_buffers, **self.progress_bar_options)

Check warning on line 307 in src/hdmf/data_utils.py

View check run for this annotation

Codecov / codecov/patch

src/hdmf/data_utils.py#L307

Added line #L307 was not covered by tests
except ImportError:
warn(
"You must install tqdm to use the progress bar feature (pip install tqdm)! "
Expand Down
Loading