-
Notifications
You must be signed in to change notification settings - Fork 0
Write Output Deep Dive
write_output() in src/indicators.py builds a path and writes a polars.DataFrame using asyncio.to_thread so file I/O does not block the event loop.
write_output(df, dir, output_file, ticker, period, timeframe, type)
-
type: the--formatvalue (csv,parquet, …) — used to choose extension and writer. -
timeframe: passed through for auto-generated filenames whenoutput_fileisNone.
Let type be the format string (e.g. csv). The final file path is chosen roughly as:
-
output_fileset,dirset,typeisNone
Joindirwithoutput_file[0](see quirks below). -
output_fileset,dirset,typenotNone
Joindirwith{basename}.{type}where basename is derived fromoutput_file[0](see quirks). -
output_fileisNone,dirset
{dir}/{ticker}_{period}_{timeframe}.{type} -
output_fileisNone,dirisNone
{ticker}_{period}_{timeframe}.{type}
The branches use output_file[0] as if output_file were a one-element sequence. In Python, indexing a string with [0] returns the first character, not the filename. When run_main passes a normal string from -o out.csv, output_file[0] is "o", not "out.csv".
Practical guidance:
- Prefer auto naming (
-donly, no-o) or verify output paths on your version. - If you need predictable names, confirm behavior with a dry run or inspect written paths in logs.
Auto names use f"{ticker}_{period}_{timeframe}.{type}". If timeframe is a dict (timeframe JSON), the string representation may be unsuitable as a filename segment. Prefer explicit -o / outputs.txt patterns or a single string -t when filenames must be clean.
| Extension | Polars method |
|---|---|
.csv |
write_csv |
.parquet |
write_parquet |
.json |
write_json |
.xlsx |
write_excel |
.avro |
write_avro |
| else | falls back to write_csv
|
If dir is set and does not exist, os.makedirs creates it.
Related pages:
- Getting Started
- CLI Reference
- Configuration & Templates
- Indicators (Overview)
- Output Formats
- Advanced Usage
- Troubleshooting
- Pipeline
- CLI Parsing
- Data Source (Yahoo Finance)
- Source Data Deep Dive
- Schema Normalization
- Data Shape Invariants
- Output Writing
- Write Output Deep Dive
- Config Resolution
- Polars Engine
- Source Modules
- Testing
- Performance
- Indicators Engine
- Reproducibility