contract.utils¶
print_data_stream_tree ¶
print_data_stream_tree(
node: DataStream,
prefix: str = "",
is_last: bool = True,
parents: list[bool] = [],
show_params: bool = False,
show_type: bool = False,
show_missing_indicator: bool = True,
) -> str
Generates a tree representation of a data stream hierarchy.
Creates a formatted string displaying the hierarchical structure of a data stream and its children as a tree with branch indicators and icons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
DataStream
|
The data stream node to start printing from. |
required |
prefix
|
str
|
Prefix string to prepend to each line, used for indentation. |
''
|
is_last
|
bool
|
Whether this node is the last child of its parent. |
True
|
parents
|
list[bool]
|
List tracking whether each ancestor was a last child, used for drawing branches. |
[]
|
show_params
|
bool
|
Whether to render parameters of the datastream. |
False
|
show_type
|
bool
|
Whether to render the class name of the datastream. |
False
|
show_missing_indicator
|
bool
|
Whether to render the missing data indicator. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted string representing the data stream tree. |
Examples:
from contraqctor.contract import Dataset, csv, json
from contraqctor.contract.utils import print_data_stream_tree
# Create a dataset with streams
csv_stream = csv.Csv("data", reader_params=csv.CsvParams(path="data.csv"))
json_stream = json.Json("config", reader_params=json.JsonParams(path="config.json"))
dataset = Dataset("experiment", [csv_stream, json_stream], version="1.0.0")
# Print the tree
tree = print_data_stream_tree(dataset)
print(tree)
# Output:
# 📂 experiment
# ├── 📄 data
# └── 📄 config
Source code in src/contraqctor/contract/utils.py
4 5 6 7 8 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 55 56 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 |
|