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

Addressing progress bar issue #300

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies = [


[project.optional-dependencies]
progress = [
"tqdm"
]
test = [
"coverage",
"geopandas",
Expand Down
10 changes: 9 additions & 1 deletion src/rasterstats/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
remap_categories,
)

from tqdm import tqdm
perrygeo marked this conversation as resolved.
Show resolved Hide resolved


def raster_stats(*args, **kwargs):
"""Deprecated. Use zonal_stats instead."""
Expand All @@ -34,7 +36,13 @@ def zonal_stats(*args, **kwargs):

The only difference is that ``zonal_stats`` will
return a list rather than a generator."""
return list(gen_zonal_stats(*args, **kwargs))
progress = kwargs.get("progress")
perrygeo marked this conversation as resolved.
Show resolved Hide resolved
if progress:
stats = gen_zonal_stats(*args, **kwargs)
total = sum(1 for _ in stats)
return [stat for stat in tqdm(stats, total=total)]
else:
return list(gen_zonal_stats(*args, **kwargs))


def gen_zonal_stats(
Expand Down