data_io¶
data_io ¶
Data I/O adapters for reading and writing tabular data.
Provides unified interface for multiple data formats following the Adapter pattern.
DataReader ¶
Bases: ABC
Abstract base class for data readers.
Follows Open/Closed principle: open for extension via new readers, closed for modification.
CSVReader ¶
Bases: DataReader
CSV file reader implementation.
Initialize CSV reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to CSV file |
required |
delimiter
|
str
|
Column delimiter |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
Source code in ondine/adapters/data_io.py
ExcelReader ¶
Bases: DataReader
Excel file reader implementation.
Initialize Excel reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Excel file |
required |
sheet_name
|
str | int
|
Sheet name or index |
0
|
Source code in ondine/adapters/data_io.py
ParquetReader ¶
Bases: DataReader
Parquet file reader implementation.
Initialize Parquet reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Parquet file |
required |
Source code in ondine/adapters/data_io.py
read ¶
read_chunked ¶
Read Parquet in chunks using Polars for efficiency.
Source code in ondine/adapters/data_io.py
DataFrameReader ¶
Bases: DataReader
In-memory DataFrame reader (pass-through).
Initialize DataFrame reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
Pandas DataFrame |
required |
Source code in ondine/adapters/data_io.py
DataWriter ¶
Bases: ABC
Abstract base class for data writers.
Follows Single Responsibility: only handles data persistence.
write
abstractmethod
¶
Write data to destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame to write |
required |
path
|
Path
|
Destination path |
required |
Returns:
| Type | Description |
|---|---|
WriteConfirmation
|
WriteConfirmation with details |
Source code in ondine/adapters/data_io.py
atomic_write
abstractmethod
¶
Write data atomically (with rollback on failure).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame to write |
required |
path
|
Path
|
Destination path |
required |
Returns:
| Type | Description |
|---|---|
WriteConfirmation
|
WriteConfirmation with details |
Source code in ondine/adapters/data_io.py
CSVWriter ¶
Bases: DataWriter
CSV file writer implementation.
Initialize CSV writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delimiter
|
str
|
Column delimiter |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
Source code in ondine/adapters/data_io.py
write ¶
Write to CSV file.
Source code in ondine/adapters/data_io.py
atomic_write ¶
Write to CSV atomically.
Source code in ondine/adapters/data_io.py
ExcelWriter ¶
Bases: DataWriter
Excel file writer implementation.
write ¶
Write to Excel file.
atomic_write ¶
Write to Excel atomically.
Source code in ondine/adapters/data_io.py
ParquetWriter ¶
Bases: DataWriter
Parquet file writer implementation.
write ¶
Write to Parquet file.
atomic_write ¶
Write to Parquet atomically.
Source code in ondine/adapters/data_io.py
create_data_reader ¶
create_data_reader(source_type: DataSourceType, source_path: Path | None = None, dataframe: DataFrame | None = None, **kwargs: any) -> DataReader
Factory function to create appropriate data reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_type
|
DataSourceType
|
Type of data source |
required |
source_path
|
Path | None
|
Path to file (for file sources) |
None
|
dataframe
|
DataFrame | None
|
DataFrame (for DataFrame source) |
None
|
**kwargs
|
any
|
Additional reader-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
DataReader
|
Configured DataReader |
Raises:
| Type | Description |
|---|---|
ValueError
|
If source type not supported or parameters invalid |
Source code in ondine/adapters/data_io.py
create_data_writer ¶
Factory function to create appropriate data writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination_type
|
DataSourceType
|
Type of destination |
required |
Returns:
| Type | Description |
|---|---|
DataWriter
|
Configured DataWriter |
Raises:
| Type | Description |
|---|---|
ValueError
|
If destination type not supported |