helper
Helper functions for data loading with progress indication in Streamlit.
This module provides cached data loading functions for CSV and Parquet files, as well as utilities to initialize Streamlit session state from preprocessed datasets. All functions use Polars for efficient DataFrame operations and integrate with Streamlit's caching and UI feedback mechanisms.
custom_exception_handler ¶
custom_exception_handler(exception)
Handle exceptions with logging and user-friendly Streamlit display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exception
|
Exception
|
The exception instance to handle. |
required |
Note
This function logs the full exception traceback and displays a user-friendly error message in the Streamlit UI instead of showing the raw Python traceback.
Source code in src/mangetamain/utils/helper.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
load_csv_with_progress ¶
load_csv_with_progress(file_path)
Read a CSV file into a Polars DataFrame while showing a Streamlit spinner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the CSV file to read. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A tuple (df, load_time) where |
float
|
|
Source code in src/mangetamain/utils/helper.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
load_data_from_parquet_and_pickle ¶
load_data_from_parquet_and_pickle()
Load ALL application data ONCE and cache it globally across all users.
This function is called once per application lifecycle. The first user will trigger the data loading (90s), but all subsequent users will get instant access (<0.01s) thanks to @st.cache_resource.
The function reads several precomputed parquet files and returns the resulting Polars DataFrames / Series as a tuple.
Source code in src/mangetamain/utils/helper.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
load_parquet_with_progress ¶
load_parquet_with_progress(file_path)
Read a Parquet file into a Polars DataFrame (cached globally with zero-copy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the Parquet file to read. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A Polars DataFrame loaded from the specified parquet file. |
Source code in src/mangetamain/utils/helper.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |