|
7 | 7 |
|
8 | 8 | import inspect |
9 | 9 | import itertools |
| 10 | +import logging |
10 | 11 | import os |
11 | 12 | import platform |
12 | 13 | import shutil |
|
62 | 63 |
|
63 | 64 | SETTINGS = MAPIClientSettings() # type: ignore |
64 | 65 |
|
| 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 | + |
65 | 74 |
|
66 | 75 | class _DictLikeAccess(BaseModel): |
67 | 76 | """Define a pydantic mix-in which permits dict-like access to model fields.""" |
@@ -553,16 +562,17 @@ def _query_resource( |
553 | 562 | if DeltaTable.is_deltatable(target_path): |
554 | 563 | if self.force_renew: |
555 | 564 | 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}..." |
559 | 567 | ) |
560 | 568 | os.makedirs(target_path, exist_ok=True) |
561 | 569 | 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.", |
566 | 576 | ) |
567 | 577 |
|
568 | 578 | return { |
@@ -654,15 +664,20 @@ def _flush(accumulator, group): |
654 | 664 | if accumulator: |
655 | 665 | _flush(accumulator, group + 1) |
656 | 666 |
|
| 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 | + |
657 | 673 | convert_to_deltalake(target_path) |
658 | 674 |
|
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/" |
664 | 678 | ) |
665 | 679 |
|
| 680 | + |
666 | 681 | return { |
667 | 682 | "data": MPDataset( |
668 | 683 | path=target_path, |
@@ -1537,7 +1552,3 @@ class MPRestError(Exception): |
1537 | 1552 |
|
1538 | 1553 | class MPRestWarning(Warning): |
1539 | 1554 | """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