owid-datautils 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- owid/datautils/__init__.py +3 -0
- owid/datautils/checks.py +1 -0
- owid/datautils/common.py +44 -0
- owid/datautils/dataframes.py +739 -0
- owid/datautils/decorators.py +91 -0
- owid/datautils/format/__init__.py +7 -0
- owid/datautils/format/numbers.py +304 -0
- owid/datautils/google/__init__.py +7 -0
- owid/datautils/google/api.py +136 -0
- owid/datautils/google/config.py +117 -0
- owid/datautils/google/sheets.py +134 -0
- owid/datautils/io/__init__.py +14 -0
- owid/datautils/io/archive.py +84 -0
- owid/datautils/io/df.py +163 -0
- owid/datautils/io/json.py +78 -0
- owid/datautils/ui.py +32 -0
- owid/datautils/web.py +106 -0
- owid_datautils-0.6.1.dist-info/METADATA +20 -0
- owid_datautils-0.6.1.dist-info/RECORD +21 -0
- owid_datautils-0.6.1.dist-info/WHEEL +4 -0
- owid_datautils-0.6.1.dist-info/licenses/LICENSE +21 -0
owid/datautils/checks.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Utils related to sanity checks of datasets."""
|
owid/datautils/common.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Common objects shared by other modules."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Any, List, Set, Union, cast
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ExceptionFromDocstring(Exception):
|
|
8
|
+
"""Exception that returns its own docstring, if no message is explicitly given."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, exception_message: Union[str, None] = None, *args: Any):
|
|
11
|
+
super().__init__(exception_message or self.__doc__, *args)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ExceptionFromDocstringWithKwargs(Exception):
|
|
15
|
+
"""Exception that returns its own docstring, if no message is explicitly given."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, exception_message: Union[str, None] = None, *args: Any, **kwargs: Any):
|
|
18
|
+
text = cast(str, exception_message or self.__doc__)
|
|
19
|
+
if kwargs:
|
|
20
|
+
additional_text = ", ".join([f"{key}: {value}" for key, value in kwargs.items()])
|
|
21
|
+
if additional_text is not None:
|
|
22
|
+
text += " " + additional_text
|
|
23
|
+
super().__init__(text, *args)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def warn_on_list_of_entities(
|
|
27
|
+
list_of_entities: Union[List[Any], Set[Any]], warning_message: str, show_list: bool
|
|
28
|
+
) -> None:
|
|
29
|
+
"""Raise a warning with a custom message, and optionally print a list of affected elements.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
list_of_entities : list or set
|
|
34
|
+
Elements to optionally print one by one (only relevant if show_list is True).
|
|
35
|
+
warning_message : str
|
|
36
|
+
Warning message.
|
|
37
|
+
show_list : bool
|
|
38
|
+
True to print a list of affected entities.
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
warnings.warn(warning_message)
|
|
42
|
+
if show_list:
|
|
43
|
+
print(warning_message)
|
|
44
|
+
print("\n".join(["* " + str(entity) for entity in list_of_entities]))
|