Context manager
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of
waterfall-logging.context_manager
.
waterfall
waterfall(log: Waterfall, variable_names: List[str], markdown_kwargs: Optional[Dict] = None)
Waterfall context manager decorator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log |
Waterfall
|
Waterfall object |
required |
variable_names |
List
|
array of variables names to log waterfall |
required |
markdown_kwargs |
dict
|
keyword arguments to save the markdown with to_markdown(**markdown_kwargs) |
None
|
Examples:
>>> import pandas as pd
>>> import numpy as np
>>> from waterfall_logging.log import PandasWaterfall
>>> from waterfall_logging.context_manager import waterfall
>>> waterfall_log = PandasWaterfall(table_name='context_manager_example', columns=['col1'])
>>> @waterfall(log=waterfall_log, variable_names=['table'], markdown_kwargs={'buf': 'ctx_manager_example.md'})
... def main():
... table = pd.DataFrame({'col1': [0, np.nan, 1, 2, 3], 'col2': [3, 4, np.nan, 5, 6]})
... table.dropna(axis=0)
...
>>> main()
>>> print(waterfall_log.to_markdown())
| Table | col1 | Δ col1 | Rows | Δ Rows | Reason | Configurations flag |
|:------------------------|-------:|---------:|-------:|---------:|:---------|:----------------------|
| context_manager_example | 5 | 0 | 5 | 0 | | |
>>> print("The `waterfall_log` is also saved in the file `ctx_manager_example.md`!")
Returns:
Name | Type | Description |
---|---|---|
decorator |
Callable
|
decorator object |
Source code in waterfall_logging/context_manager.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
WaterfallContext
Waterfall context to trace any function calls inside the context.
Source code in waterfall_logging/context_manager.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
__enter__
__enter__()
Enter the trace.
Source code in waterfall_logging/context_manager.py
77 78 79 |
|
__exit__
__exit__(*args, **kwargs)
Exit the trace and export Waterfall object to Markdown.
Source code in waterfall_logging/context_manager.py
81 82 83 84 |
|
__init__
__init__(log: Waterfall, name: str, variable_names: List[str], markdown_kwargs: Optional[Dict] = None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log |
Waterfall
|
waterfall logging object |
required |
name |
str
|
name of the function that is to de debugged |
required |
variable_names |
List
|
array of variables names to log waterfall |
required |
markdown_kwargs |
dict
|
keyword arguments to save the markdown with to_markdown(**markdown_kwargs) |
None
|
Source code in waterfall_logging/context_manager.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
trace_calls
trace_calls(frame: types.FrameType, event, arg: Any)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
types.FrameType
|
a tracing frame |
required |
event |
str
|
a tracing event |
required |
arg |
Any
|
a tracing argument |
required |
Returns:
Name | Type | Description |
---|---|---|
traced_lines |
types.MethodType
|
traced lines |
Source code in waterfall_logging/context_manager.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
trace_lines
trace_lines(frame: types.FrameType, event: str, arg: Any) -> None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
types.FrameType
|
a tracing frame |
required |
event |
str
|
a tracing event |
required |
arg |
Any
|
a tracing argument |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in waterfall_logging/context_manager.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|