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.
@@ -0,0 +1,3 @@
1
+ """Library to support the work of the Data Team at Our World in Data."""
2
+
3
+ __version__ = "0.5.3"
@@ -0,0 +1 @@
1
+ """Utils related to sanity checks of datasets."""
@@ -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]))