Skip to content

Commit 3a44b4f

Browse files
committed
opt for module level logging over warnings lib
1 parent 03b38e7 commit 3a44b4f

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

mp_api/client/core/client.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import inspect
99
import itertools
10+
import logging
1011
import os
1112
import platform
1213
import shutil
@@ -62,6 +63,14 @@
6263

6364
SETTINGS = MAPIClientSettings() # type: ignore
6465

66+
hdlr = logging.StreamHandler()
67+
fmt = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
68+
hdlr.setFormatter(fmt)
69+
70+
logger = logging.getLogger(__name__)
71+
logger.setLevel(logging.INFO)
72+
logger.addHandler(hdlr)
73+
6574

6675
class _DictLikeAccess(BaseModel):
6776
"""Define a pydantic mix-in which permits dict-like access to model fields."""
@@ -553,16 +562,17 @@ def _query_resource(
553562
if DeltaTable.is_deltatable(target_path):
554563
if self.force_renew:
555564
shutil.rmtree(target_path)
556-
warnings.warn(
557-
f"Regenerating {suffix} dataset at {target_path}...",
558-
MPLocalDatasetWarning,
565+
logger.warning(
566+
f"Regenerating {suffix} dataset at {target_path}..."
559567
)
560568
os.makedirs(target_path, exist_ok=True)
561569
else:
562-
warnings.warn(
563-
f"Dataset for {suffix} already exists at {target_path}, delete or move existing dataset "
564-
"or re-run search query with MPRester(force_renew=True)",
565-
MPLocalDatasetWarning,
570+
logger.warning(
571+
f"Dataset for {suffix} already exists at {target_path}, returning existing dataset."
572+
)
573+
logger.info(
574+
"Delete or move existing dataset or re-run search query with MPRester(force_renew=True) "
575+
"to refresh local dataset.",
566576
)
567577

568578
return {
@@ -654,15 +664,20 @@ def _flush(accumulator, group):
654664
if accumulator:
655665
_flush(accumulator, group + 1)
656666

667+
if pbar is not None:
668+
pbar.close()
669+
670+
logger.info(f"Dataset for {suffix} written to {target_path}")
671+
logger.info("Converting to DeltaTable...")
672+
657673
convert_to_deltalake(target_path)
658674

659-
warnings.warn(
660-
f"Dataset for {suffix} written to {target_path}. It is recommended to optimize "
661-
"the table according to your usage patterns prior to running intensive workloads, "
662-
"see: https://delta-io.github.io/delta-rs/delta-lake-best-practices/#optimizing-table-layout",
663-
MPLocalDatasetWarning,
675+
logger.info(
676+
"Consult the delta-rs and pyarrow documentation for advanced usage: "
677+
"delta-io.github.io/delta-rs/, arrow.apache.org/docs/python/"
664678
)
665679

680+
666681
return {
667682
"data": MPDataset(
668683
path=target_path,
@@ -1537,7 +1552,3 @@ class MPRestError(Exception):
15371552

15381553
class MPRestWarning(Warning):
15391554
"""Raised when a query is malformed but interpretable."""
1540-
1541-
1542-
class MPLocalDatasetWarning(Warning):
1543-
"""Raised when unrecoverable actions are performed on a local dataset."""

0 commit comments

Comments
 (0)