pub fn read_financial_data<P: AsRef<Path>>(
file_path: P,
) -> PolarsResult<(DataFrame, FinancialColumns)>
Expand description
Read a financial data file (CSV or Parquet) and standardize column names
This function automatically detects and handles various aspects of financial data files:
- File type (CSV or Parquet) is detected from the file extension
- For CSV files:
- Automatically detects if the file has headers by checking for common financial column names
- Tries multiple common delimiters (comma, semicolon, tab, pipe) until successful
- For Parquet files:
- Directly reads the file as Parquet format is self-describing
The function attempts to identify and standardize OHLCV (Open, High, Low, Close, Volume) columns whether or not the file has headers. It handles various common column name variations and automatically maps them to standardized names.
§Column Name Handling
- Case-insensitive: Column names are handled in a case-insensitive manner (DATE, Date, date all match)
- Abbreviations: Common abbreviations are supported:
- Date: “date”, “dt”, “time”, “datetime”, “timestamp”
- Open: “open”, “o”, “opening”
- High: “high”, “h”, “highest”
- Low: “low”, “l”, “lowest”
- Close: “close”, “c”, “closing”
- Volume: “volume”, “vol”, “v”
§Arguments
file_path
- Path to the file (must have .csv or .parquet extension)
§Returns
A tuple with (DataFrame, FinancialColumns) where FinancialColumns contains the standardized column name mapping
§Example
use ta_lib_in_rust::util::file_utils::read_financial_data;
// Read a CSV file - automatically detects headers and delimiter
let (df, columns) = read_financial_data("data/prices.csv").unwrap();
println!("Close column: {:?}", columns.close);
// Read a Parquet file
let (df, columns) = read_financial_data("data/prices.parquet").unwrap();
println!("Volume column: {:?}", columns.volume);
§Supported File Types
- CSV files (
.csv
extension)- Automatically detects headers
- Supports multiple delimiters: comma (,), semicolon (;), tab (\t), pipe (|)
- Parquet files (
.parquet
extension)
§Error Handling
The function will return an error if:
- The file extension is not supported
- The file cannot be read
- No valid delimiter is found for CSV files
- The file format is invalid