Skip to content

Commit 26998b8

Browse files
Make progress bar dependent on log level (#124)
1 parent 70f222e commit 26998b8

7 files changed

Lines changed: 22 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python-version: ["3.9", "3.10", "3.11"]
16+
python-version: ["3.10", "3.11", "3.12"]
1717

1818
steps:
1919
- uses: actions/checkout@v2
@@ -38,4 +38,4 @@ jobs:
3838

3939
- name: Test doc build with tox
4040
run: tox -e docs
41-
if: ${{ (matrix.python-version == '3.10') && (matrix.os == 'ubuntu-latest')}}
41+
if: ${{ (matrix.python-version == '3.11') && (matrix.os == 'ubuntu-latest')}}

.github/workflows/deploy_public.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ jobs:
3535
steps:
3636
- uses: actions/checkout@v3
3737

38-
- name: Set up Python 3.10
38+
- name: Set up Python 3.11
3939
uses: actions/setup-python@v4
4040
with:
41-
python-version: "3.10"
41+
python-version: "3.11"
4242

4343
- name: Install dependencies
4444
run: |

datareservoirio/appdirs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
https://github.com/pypa/pip/blob/master/src/pip/_internal/utils/appdirs.py and
44
modified to suit our purposes.
55
"""
6+
67
from __future__ import absolute_import, division, print_function
78

89
import os

datareservoirio/client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ def get_samples_aggregate_page(url):
543543
timeout=_TIMEOUT_DEAULT,
544544
)
545545

546-
progress_bar = tqdm(unit=" pages", desc="Downloading aggregate data")
546+
if log.getEffectiveLevel() < logging.WARNING:
547+
progress_bar = tqdm(unit=" pages", desc="Downloading aggregate data")
548+
547549
while next_page_link:
548550
response = get_samples_aggregate_page(next_page_link)
549551
response.raise_for_status()
@@ -559,17 +561,19 @@ def get_samples_aggregate_page(url):
559561
]
560562

561563
# update the progress bar
562-
if content:
564+
if content and log.getEffectiveLevel() < logging.WARNING:
563565
progress_bar.update(1)
564566

565567
new_df = pd.DataFrame(
566568
content, columns=("index", "values"), copy=False
567569
).astype({"values": "float64"}, errors="ignore")
568570

569571
df = pd.concat([df, new_df])
570-
571-
progress_bar.close()
572-
series = df.set_index("index").squeeze("columns").copy(deep=True)
572+
if log.getEffectiveLevel() < logging.WARNING:
573+
progress_bar.close()
574+
series = (
575+
df.infer_objects().set_index("index").squeeze("columns").copy(deep=True)
576+
)
573577

574578
return series
575579

docs/user_guide/advanced_config.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ Logging
107107
To simplify debugging, enable logging for the logger named 'datareservoirio'. This is especially helpful if you experience undesired behavior in your application.
108108

109109
If your logging requirements are solely related to :py:mod:`datareservoirio`, you can use the following code. This will provide you with an understanding of the progress made in some
110-
of the processes in the package. It is recommended to use this logging.
110+
of the processes in the package.
111+
In particular, when using :py:meth:`Client.get_samples_aggregate`, lowering the log level below WARNING triggers a progress bar during data collection.
112+
The default log level for the logger named 'datareservoirio' is WARNING.
113+
It is recommended to use this logging.
111114

112115
.. code-block:: python
113116

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ dynamic = ["version"]
1111
description = "DataReservoir.io Python API"
1212
readme = "README.rst"
1313
license = { file="LICENSE" }
14-
requires-python = ">3.9"
14+
requires-python = ">3.10"
1515
classifiers = [
1616
"Development Status :: 5 - Production/Stable",
1717
"License :: OSI Approved :: MIT License",
1818
"Operating System :: OS Independent",
19-
"Programming Language :: Python :: 3.9",
2019
"Programming Language :: Python :: 3.10",
2120
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
2222
]
2323
dependencies = [
2424
"numpy",
@@ -69,7 +69,7 @@ deps =
6969
7070
7171
[testenv:docs]
72-
basepython = python3.10
72+
basepython = python3.11
7373
commands = sphinx-build -W -b html -d {toxworkdir}/docs_doctree docs {toxworkdir}/docs_out
7474
deps =
7575
sphinx==5.3.0

tests/response_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Note that ``url`` is defined as part of the key in RESPONSE_CASES.
1616
See ``requests.Response`` source code for more details.
1717
"""
18+
1819
from pathlib import Path
1920

2021
TEST_PATH = Path(__file__).parent

0 commit comments

Comments
 (0)