fsspeckit.datasets API Reference¶
datasets
¶
Dataset-level operations for fsspeckit.
This package contains dataset-specific functionality including: - DuckDB parquet handlers for high-performance dataset operations - PyArrow utilities for schema management and type conversion - Dataset merging and optimization tools
Classes¶
fsspeckit.datasets.DuckDBParquetHandler
¶
DuckDBParquetHandler(
storage_options: Optional[
Union[BaseStorageOptions, dict]
] = None,
filesystem: Optional[AbstractFileSystem] = None,
)
Bases: DuckDBDatasetIO
Backward compatibility wrapper for DuckDBParquetHandler.
This class has been refactored into: - DuckDBConnection: for connection management - DuckDBDatasetIO: for dataset I/O operations
For new code, consider using DuckDBConnection and DuckDBDatasetIO directly.
Initialize DuckDB parquet handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_options
|
Optional[Union[BaseStorageOptions, dict]]
|
Storage configuration options (deprecated) |
None
|
filesystem
|
Optional[AbstractFileSystem]
|
Filesystem instance (deprecated) |
None
|
Source code in src/fsspeckit/datasets/duckdb.py
Functions¶
fsspeckit.datasets.cast_schema
¶
Cast a PyArrow table to a target schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
Source table |
required |
schema
|
Schema
|
Target schema |
required |
Returns:
| Type | Description |
|---|---|
Table
|
Table cast to target schema |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.collect_dataset_stats_pyarrow
¶
collect_dataset_stats_pyarrow(
path: str,
filesystem: AbstractFileSystem | None = None,
partition_filter: list[str] | None = None,
) -> dict[str, Any]
Collect file-level statistics for a parquet dataset using shared core logic.
This function delegates to the shared fsspeckit.core.maintenance.collect_dataset_stats
function, ensuring consistent dataset discovery and statistics across both DuckDB
and PyArrow backends.
The helper walks the given dataset directory on the provided filesystem, discovers parquet files (recursively), and returns basic statistics:
- Per-file path, size in bytes, and number of rows
- Aggregated total bytes and total rows
The function is intentionally streaming/metadata-driven and never
materializes the full dataset as a single :class:pyarrow.Table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Root directory of the parquet dataset. |
required |
filesystem
|
AbstractFileSystem | None
|
Optional fsspec filesystem. If omitted, a local "file" filesystem is used. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefix filters
(e.g. ["date=2025-11-04"]). Only files whose path relative to
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist or no parquet files match the optional partition filter. |
Note
This is a thin wrapper around the shared core function. See
:func:fsspeckit.core.maintenance.collect_dataset_stats for the
authoritative implementation.
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
fsspeckit.datasets.compact_parquet_dataset_pyarrow
¶
compact_parquet_dataset_pyarrow(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
dry_run: bool = False,
filesystem: AbstractFileSystem | None = None,
) -> dict[str, Any]
Compact a parquet dataset directory into fewer larger files using PyArrow and shared planning.
Groups small files based on size (MB) and/or row thresholds, rewrites grouped files into new parquet files, and optionally changes compression. Supports a dry-run mode that returns the compaction plan without modifying files.
The implementation uses the shared core planning algorithm for consistent behavior across backends. It processes data in a group-based, streaming fashion: it reads only the files in a given group into memory when processing that group and never materializes the entire dataset as a single table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset root directory (local path or fsspec URL). |
required |
target_mb_per_file
|
int | None
|
Optional max output size per file; must be > 0. |
None
|
target_rows_per_file
|
int | None
|
Optional max rows per output file; must be > 0. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefixes (e.g. |
None
|
compression
|
str | None
|
Optional parquet compression codec; defaults to |
None
|
dry_run
|
bool
|
When |
False
|
filesystem
|
AbstractFileSystem | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A stats dictionary describing before/after file counts, total bytes, |
dict[str, Any]
|
rewritten bytes, and optional |
dict[str, Any]
|
The structure follows the canonical |
Raises:
| Type | Description |
|---|---|
ValueError
|
If thresholds are invalid or no files match partition filter. |
FileNotFoundError
|
If the path does not exist. |
Example
Note
This function delegates dataset discovery and compaction planning to the
shared fsspeckit.core.maintenance module, ensuring consistent behavior
across DuckDB and PyArrow backends.
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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 212 213 214 215 216 217 218 | |
fsspeckit.datasets.convert_large_types_to_normal
¶
Convert large types (like large_string) to normal types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
PyArrow schema |
required |
Returns:
| Type | Description |
|---|---|
Schema
|
Schema with large types converted |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.opt_dtype_pa
¶
Optimize dtypes in a PyArrow table based on data analysis.
This function analyzes the data in each column and attempts to downcast to more appropriate types (e.g., int64 -> int32, float64 -> float32, string -> int/bool where applicable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
PyArrow table to optimize |
required |
strict
|
bool
|
Whether to use strict type checking |
False
|
columns
|
list[str] | None
|
List of columns to optimize (None for all) |
None
|
Returns:
| Type | Description |
|---|---|
Table
|
Table with optimized dtypes |
Example
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.optimize_parquet_dataset_pyarrow
¶
optimize_parquet_dataset_pyarrow(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
filesystem: AbstractFileSystem | None = None,
verbose: bool = False,
) -> dict[str, Any]
Optimize a parquet dataset through compaction and optional statistics recalculation.
This is a convenience function that combines compaction with optional statistics recalculation. It's particularly useful after many small write operations have created a large number of small files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset root directory |
required |
target_mb_per_file
|
int | None
|
Target size per file in MB |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec to use |
None
|
filesystem
|
AbstractFileSystem | None
|
Optional filesystem instance |
None
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Optimization statistics |
Example
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
fsspeckit.datasets.unify_schemas_pa
¶
unify_schemas_pa(
schemas: list[Schema],
standardize_timezones: bool = True,
verbose: bool = False,
) -> Schema
Unify multiple PyArrow schemas into a single schema.
This function handles type conflicts by: 1. Finding fields with conflicting types 2. Attempting to normalize compatible types 3. Using fallback strategies for incompatible types 4. Removing problematic fields if necessary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of schemas to unify |
required |
standardize_timezones
|
bool
|
Whether to standardize timezone info |
True
|
verbose
|
bool
|
Whether to print conflict information |
False
|
Returns:
| Type | Description |
|---|---|
Schema
|
Unified PyArrow schema |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schemas cannot be unified |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
Modules¶
fsspeckit.datasets.duckdb
¶
Re-export module for backward compatibility.
This module has been decomposed into focused submodules: - duckdb_connection: Connection management and filesystem registration - duckdb_dataset: Dataset I/O and maintenance operations
All public APIs are re-exported here to maintain backward compatibility. New code should import directly from the submodules for better organization.
Classes¶
fsspeckit.datasets.duckdb.DuckDBConnection
¶
Manages DuckDB connection lifecycle and filesystem registration.
This class is responsible for: - Creating and managing DuckDB connections - Registering fsspec filesystems with DuckDB - Connection cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filesystem
|
AbstractFileSystem | None
|
fsspec filesystem instance to use |
None
|
Initialize DuckDB connection manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filesystem
|
AbstractFileSystem | None
|
Filesystem to use. Defaults to local filesystem. |
None
|
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb.DuckDBConnection.connection
property
¶Get active DuckDB connection, creating it if necessary.
Returns:
| Type | Description |
|---|---|
Any
|
Active DuckDB connection |
fsspeckit.datasets.duckdb.DuckDBConnection.filesystem
property
¶Get the filesystem instance.
Returns:
| Type | Description |
|---|---|
AbstractFileSystem
|
Filesystem instance |
fsspeckit.datasets.duckdb.DuckDBConnection.__del__
¶ fsspeckit.datasets.duckdb.DuckDBConnection.__enter__
¶ fsspeckit.datasets.duckdb.DuckDBConnection.__exit__
¶ fsspeckit.datasets.duckdb.DuckDBConnection.close
¶Close the connection and clean up resources.
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb.DuckDBConnection.execute_sql
¶Execute a SQL query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
SQL query to execute |
required |
parameters
|
list[Any] | None
|
Optional query parameters |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Query result |
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb.DuckDBDatasetIO
¶
DuckDBDatasetIO(connection: DuckDBConnection)
DuckDB-based dataset I/O operations.
This class provides methods for reading and writing parquet files and datasets using DuckDB's high-performance parquet engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
DuckDBConnection
|
DuckDB connection manager |
required |
Initialize DuckDB dataset I/O.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
DuckDBConnection
|
DuckDB connection manager |
required |
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb.DuckDBDatasetIO.compact_parquet_dataset
¶compact_parquet_dataset(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
dry_run: bool = False,
verbose: bool = False,
) -> dict[str, Any]
Compact a parquet dataset using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset path |
required |
target_mb_per_file
|
int | None
|
Target size per file |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec |
None
|
dry_run
|
bool
|
Whether to perform a dry run |
False
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Compaction statistics |
Source code in src/fsspeckit/datasets/duckdb_dataset.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
fsspeckit.datasets.duckdb.DuckDBDatasetIO.merge_parquet_dataset
¶merge_parquet_dataset(
sources: list[str],
output_path: str,
target: str | None = None,
strategy: str | MergeStrategy = "deduplicate",
key_columns: list[str] | str | None = None,
compression: str | None = None,
verbose: bool = False,
**kwargs: Any,
) -> MergeStats
Merge multiple parquet datasets using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
list[str]
|
List of source dataset paths |
required |
output_path
|
str
|
Path for merged output |
required |
target
|
str | None
|
Target dataset path (for upsert/update strategies) |
None
|
strategy
|
str | MergeStrategy
|
Merge strategy to use |
'deduplicate'
|
key_columns
|
list[str] | str | None
|
Key columns for merging |
None
|
compression
|
str | None
|
Output compression codec |
None
|
verbose
|
bool
|
Print progress information |
False
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
MergeStats
|
MergeStats with merge statistics |
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb.DuckDBDatasetIO.optimize_parquet_dataset
¶optimize_parquet_dataset(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
verbose: bool = False,
) -> dict[str, Any]
Optimize a parquet dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset path |
required |
target_mb_per_file
|
int | None
|
Target size per file |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec |
None
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Optimization statistics |
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb.DuckDBDatasetIO.read_parquet
¶read_parquet(
path: str,
columns: list[str] | None = None,
filter: str | None = None,
use_threads: bool = True,
) -> Table
Read parquet file(s) using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to parquet file or directory |
required |
columns
|
list[str] | None
|
Optional list of columns to read |
None
|
filter
|
str | None
|
Optional SQL WHERE clause |
None
|
use_threads
|
bool
|
Whether to use parallel reading |
True
|
Returns:
| Type | Description |
|---|---|
Table
|
PyArrow table containing the data |
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb.DuckDBDatasetIO.write_parquet
¶write_parquet(
data: Table | list[Table],
path: str,
compression: str | None = "snappy",
row_group_size: int | None = None,
use_threads: bool = True,
) -> None
Write parquet file using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Table | list[Table]
|
PyArrow table or list of tables to write |
required |
path
|
str
|
Output file path |
required |
compression
|
str | None
|
Compression codec to use |
'snappy'
|
row_group_size
|
int | None
|
Rows per row group |
None
|
use_threads
|
bool
|
Whether to use parallel writing |
True
|
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb.DuckDBDatasetIO.write_parquet_dataset
¶write_parquet_dataset(
data: Table | list[Table],
path: str,
basename_template: str | None = None,
schema: Schema | None = None,
partition_by: str | list[str] | None = None,
compression: str | None = "snappy",
max_rows_per_file: int | None = 5000000,
row_group_size: int | None = 500000,
use_threads: bool = True,
) -> None
Write a parquet dataset using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Table | list[Table]
|
PyArrow table or list of tables to write |
required |
path
|
str
|
Output directory path |
required |
basename_template
|
str | None
|
Template for file names |
None
|
schema
|
Schema | None
|
Optional schema to enforce |
None
|
partition_by
|
str | list[str] | None
|
Column(s) to partition by |
None
|
compression
|
str | None
|
Compression codec |
'snappy'
|
max_rows_per_file
|
int | None
|
Maximum rows per file |
5000000
|
row_group_size
|
int | None
|
Rows per row group |
500000
|
use_threads
|
bool
|
Whether to use parallel writing |
True
|
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
fsspeckit.datasets.duckdb.DuckDBParquetHandler
¶
DuckDBParquetHandler(
storage_options: Optional[
Union[BaseStorageOptions, dict]
] = None,
filesystem: Optional[AbstractFileSystem] = None,
)
Bases: DuckDBDatasetIO
Backward compatibility wrapper for DuckDBParquetHandler.
This class has been refactored into: - DuckDBConnection: for connection management - DuckDBDatasetIO: for dataset I/O operations
For new code, consider using DuckDBConnection and DuckDBDatasetIO directly.
Initialize DuckDB parquet handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage_options
|
Optional[Union[BaseStorageOptions, dict]]
|
Storage configuration options (deprecated) |
None
|
filesystem
|
Optional[AbstractFileSystem]
|
Filesystem instance (deprecated) |
None
|
Source code in src/fsspeckit/datasets/duckdb.py
fsspeckit.datasets.duckdb.DuckDBParquetHandler.__del__
¶ fsspeckit.datasets.duckdb.DuckDBParquetHandler.__enter__
¶ fsspeckit.datasets.duckdb.DuckDBParquetHandler.__exit__
¶ fsspeckit.datasets.duckdb.DuckDBParquetHandler.close
¶ fsspeckit.datasets.duckdb.DuckDBParquetHandler.execute_sql
¶Functions¶
fsspeckit.datasets.duckdb.create_duckdb_connection
¶
create_duckdb_connection(
filesystem: AbstractFileSystem | None = None,
) -> DuckDBConnection
Create a DuckDB connection manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filesystem
|
AbstractFileSystem | None
|
fsspec filesystem to use |
None
|
Returns:
| Type | Description |
|---|---|
DuckDBConnection
|
DuckDB connection manager |
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb_cleanup_helpers
¶
fsspeckit.datasets.duckdb_connection
¶
DuckDB connection and filesystem registration helpers.
This module contains functions and classes for managing DuckDB connections and integrating with fsspec filesystems.
Classes¶
fsspeckit.datasets.duckdb_connection.DuckDBConnection
¶
Manages DuckDB connection lifecycle and filesystem registration.
This class is responsible for: - Creating and managing DuckDB connections - Registering fsspec filesystems with DuckDB - Connection cleanup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filesystem
|
AbstractFileSystem | None
|
fsspec filesystem instance to use |
None
|
Initialize DuckDB connection manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filesystem
|
AbstractFileSystem | None
|
Filesystem to use. Defaults to local filesystem. |
None
|
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb_connection.DuckDBConnection.connection
property
¶Get active DuckDB connection, creating it if necessary.
Returns:
| Type | Description |
|---|---|
Any
|
Active DuckDB connection |
fsspeckit.datasets.duckdb_connection.DuckDBConnection.filesystem
property
¶Get the filesystem instance.
Returns:
| Type | Description |
|---|---|
AbstractFileSystem
|
Filesystem instance |
fsspeckit.datasets.duckdb_connection.DuckDBConnection.__del__
¶ fsspeckit.datasets.duckdb_connection.DuckDBConnection.__enter__
¶ fsspeckit.datasets.duckdb_connection.DuckDBConnection.__exit__
¶ fsspeckit.datasets.duckdb_connection.DuckDBConnection.close
¶Close the connection and clean up resources.
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb_connection.DuckDBConnection.execute_sql
¶Execute a SQL query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
SQL query to execute |
required |
parameters
|
list[Any] | None
|
Optional query parameters |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Query result |
Source code in src/fsspeckit/datasets/duckdb_connection.py
Functions¶
fsspeckit.datasets.duckdb_connection.create_duckdb_connection
¶
create_duckdb_connection(
filesystem: AbstractFileSystem | None = None,
) -> DuckDBConnection
Create a DuckDB connection manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filesystem
|
AbstractFileSystem | None
|
fsspec filesystem to use |
None
|
Returns:
| Type | Description |
|---|---|
DuckDBConnection
|
DuckDB connection manager |
Source code in src/fsspeckit/datasets/duckdb_connection.py
fsspeckit.datasets.duckdb_dataset
¶
DuckDB dataset I/O and maintenance operations.
This module contains functions for reading, writing, and maintaining parquet datasets using DuckDB.
Classes¶
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO
¶
DuckDBDatasetIO(connection: DuckDBConnection)
DuckDB-based dataset I/O operations.
This class provides methods for reading and writing parquet files and datasets using DuckDB's high-performance parquet engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
DuckDBConnection
|
DuckDB connection manager |
required |
Initialize DuckDB dataset I/O.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
DuckDBConnection
|
DuckDB connection manager |
required |
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO.compact_parquet_dataset
¶compact_parquet_dataset(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
dry_run: bool = False,
verbose: bool = False,
) -> dict[str, Any]
Compact a parquet dataset using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset path |
required |
target_mb_per_file
|
int | None
|
Target size per file |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec |
None
|
dry_run
|
bool
|
Whether to perform a dry run |
False
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Compaction statistics |
Source code in src/fsspeckit/datasets/duckdb_dataset.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO.merge_parquet_dataset
¶merge_parquet_dataset(
sources: list[str],
output_path: str,
target: str | None = None,
strategy: str | MergeStrategy = "deduplicate",
key_columns: list[str] | str | None = None,
compression: str | None = None,
verbose: bool = False,
**kwargs: Any,
) -> MergeStats
Merge multiple parquet datasets using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
list[str]
|
List of source dataset paths |
required |
output_path
|
str
|
Path for merged output |
required |
target
|
str | None
|
Target dataset path (for upsert/update strategies) |
None
|
strategy
|
str | MergeStrategy
|
Merge strategy to use |
'deduplicate'
|
key_columns
|
list[str] | str | None
|
Key columns for merging |
None
|
compression
|
str | None
|
Output compression codec |
None
|
verbose
|
bool
|
Print progress information |
False
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
MergeStats
|
MergeStats with merge statistics |
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO.optimize_parquet_dataset
¶optimize_parquet_dataset(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
verbose: bool = False,
) -> dict[str, Any]
Optimize a parquet dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset path |
required |
target_mb_per_file
|
int | None
|
Target size per file |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec |
None
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Optimization statistics |
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO.read_parquet
¶read_parquet(
path: str,
columns: list[str] | None = None,
filter: str | None = None,
use_threads: bool = True,
) -> Table
Read parquet file(s) using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to parquet file or directory |
required |
columns
|
list[str] | None
|
Optional list of columns to read |
None
|
filter
|
str | None
|
Optional SQL WHERE clause |
None
|
use_threads
|
bool
|
Whether to use parallel reading |
True
|
Returns:
| Type | Description |
|---|---|
Table
|
PyArrow table containing the data |
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO.write_parquet
¶write_parquet(
data: Table | list[Table],
path: str,
compression: str | None = "snappy",
row_group_size: int | None = None,
use_threads: bool = True,
) -> None
Write parquet file using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Table | list[Table]
|
PyArrow table or list of tables to write |
required |
path
|
str
|
Output file path |
required |
compression
|
str | None
|
Compression codec to use |
'snappy'
|
row_group_size
|
int | None
|
Rows per row group |
None
|
use_threads
|
bool
|
Whether to use parallel writing |
True
|
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
fsspeckit.datasets.duckdb_dataset.DuckDBDatasetIO.write_parquet_dataset
¶write_parquet_dataset(
data: Table | list[Table],
path: str,
basename_template: str | None = None,
schema: Schema | None = None,
partition_by: str | list[str] | None = None,
compression: str | None = "snappy",
max_rows_per_file: int | None = 5000000,
row_group_size: int | None = 500000,
use_threads: bool = True,
) -> None
Write a parquet dataset using DuckDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Table | list[Table]
|
PyArrow table or list of tables to write |
required |
path
|
str
|
Output directory path |
required |
basename_template
|
str | None
|
Template for file names |
None
|
schema
|
Schema | None
|
Optional schema to enforce |
None
|
partition_by
|
str | list[str] | None
|
Column(s) to partition by |
None
|
compression
|
str | None
|
Compression codec |
'snappy'
|
max_rows_per_file
|
int | None
|
Maximum rows per file |
5000000
|
row_group_size
|
int | None
|
Rows per row group |
500000
|
use_threads
|
bool
|
Whether to use parallel writing |
True
|
Example
Source code in src/fsspeckit/datasets/duckdb_dataset.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
Functions¶
fsspeckit.datasets.pyarrow
¶
Re-export module for backward compatibility.
This module has been decomposed into focused submodules: - pyarrow_schema: Schema unification, type inference, and optimization - pyarrow_dataset: Dataset merge and maintenance operations
All public APIs are re-exported here to maintain backward compatibility. New code should import directly from the submodules for better organization.
Functions¶
fsspeckit.datasets.pyarrow.cast_schema
¶
Cast a PyArrow table to a target schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
Source table |
required |
schema
|
Schema
|
Target schema |
required |
Returns:
| Type | Description |
|---|---|
Table
|
Table cast to target schema |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow.collect_dataset_stats_pyarrow
¶
collect_dataset_stats_pyarrow(
path: str,
filesystem: AbstractFileSystem | None = None,
partition_filter: list[str] | None = None,
) -> dict[str, Any]
Collect file-level statistics for a parquet dataset using shared core logic.
This function delegates to the shared fsspeckit.core.maintenance.collect_dataset_stats
function, ensuring consistent dataset discovery and statistics across both DuckDB
and PyArrow backends.
The helper walks the given dataset directory on the provided filesystem, discovers parquet files (recursively), and returns basic statistics:
- Per-file path, size in bytes, and number of rows
- Aggregated total bytes and total rows
The function is intentionally streaming/metadata-driven and never
materializes the full dataset as a single :class:pyarrow.Table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Root directory of the parquet dataset. |
required |
filesystem
|
AbstractFileSystem | None
|
Optional fsspec filesystem. If omitted, a local "file" filesystem is used. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefix filters
(e.g. ["date=2025-11-04"]). Only files whose path relative to
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist or no parquet files match the optional partition filter. |
Note
This is a thin wrapper around the shared core function. See
:func:fsspeckit.core.maintenance.collect_dataset_stats for the
authoritative implementation.
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
fsspeckit.datasets.pyarrow.compact_parquet_dataset_pyarrow
¶
compact_parquet_dataset_pyarrow(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
dry_run: bool = False,
filesystem: AbstractFileSystem | None = None,
) -> dict[str, Any]
Compact a parquet dataset directory into fewer larger files using PyArrow and shared planning.
Groups small files based on size (MB) and/or row thresholds, rewrites grouped files into new parquet files, and optionally changes compression. Supports a dry-run mode that returns the compaction plan without modifying files.
The implementation uses the shared core planning algorithm for consistent behavior across backends. It processes data in a group-based, streaming fashion: it reads only the files in a given group into memory when processing that group and never materializes the entire dataset as a single table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset root directory (local path or fsspec URL). |
required |
target_mb_per_file
|
int | None
|
Optional max output size per file; must be > 0. |
None
|
target_rows_per_file
|
int | None
|
Optional max rows per output file; must be > 0. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefixes (e.g. |
None
|
compression
|
str | None
|
Optional parquet compression codec; defaults to |
None
|
dry_run
|
bool
|
When |
False
|
filesystem
|
AbstractFileSystem | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A stats dictionary describing before/after file counts, total bytes, |
dict[str, Any]
|
rewritten bytes, and optional |
dict[str, Any]
|
The structure follows the canonical |
Raises:
| Type | Description |
|---|---|
ValueError
|
If thresholds are invalid or no files match partition filter. |
FileNotFoundError
|
If the path does not exist. |
Example
Note
This function delegates dataset discovery and compaction planning to the
shared fsspeckit.core.maintenance module, ensuring consistent behavior
across DuckDB and PyArrow backends.
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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 212 213 214 215 216 217 218 | |
fsspeckit.datasets.pyarrow.convert_large_types_to_normal
¶
Convert large types (like large_string) to normal types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
PyArrow schema |
required |
Returns:
| Type | Description |
|---|---|
Schema
|
Schema with large types converted |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow.merge_parquet_dataset_pyarrow
¶
merge_parquet_dataset_pyarrow(
sources: list[str],
output_path: str,
target: str | None = None,
strategy: str | MergeStrategy = "deduplicate",
key_columns: list[str] | str | None = None,
filesystem: AbstractFileSystem | None = None,
compression: str | None = None,
row_group_size: int | None = 500000,
max_rows_per_file: int | None = 5000000,
verbose: bool = False,
**kwargs: Any,
) -> MergeStats
Merge multiple parquet datasets using PyArrow with various strategies.
This function provides dataset merging capabilities with support for: - Multiple merge strategies (upsert, insert, update, full_merge, deduplicate) - Key-based merging for relational operations - Batch processing for large datasets - Configurable output settings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
list[str]
|
List of source dataset paths |
required |
output_path
|
str
|
Path for merged output |
required |
target
|
str | None
|
Target dataset path (for upsert/update strategies) |
None
|
strategy
|
str | MergeStrategy
|
Merge strategy to use |
'deduplicate'
|
key_columns
|
list[str] | str | None
|
Key columns for merging (required for relational strategies) |
None
|
filesystem
|
AbstractFileSystem | None
|
fsspec filesystem instance |
None
|
compression
|
str | None
|
Output compression codec |
None
|
row_group_size
|
int | None
|
Rows per parquet row group |
500000
|
max_rows_per_file
|
int | None
|
Max rows per output file |
5000000
|
verbose
|
bool
|
Print progress information |
False
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
MergeStats
|
MergeStats with merge statistics |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required parameters are missing |
FileNotFoundError
|
If sources don't exist |
Example
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
fsspeckit.datasets.pyarrow.opt_dtype
¶
Optimize dtypes in a PyArrow table based on data analysis.
This function analyzes the data in each column and attempts to downcast to more appropriate types (e.g., int64 -> int32, float64 -> float32, string -> int/bool where applicable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
PyArrow table to optimize |
required |
strict
|
bool
|
Whether to use strict type checking |
False
|
columns
|
list[str] | None
|
List of columns to optimize (None for all) |
None
|
Returns:
| Type | Description |
|---|---|
Table
|
Table with optimized dtypes |
Example
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow.optimize_parquet_dataset_pyarrow
¶
optimize_parquet_dataset_pyarrow(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
filesystem: AbstractFileSystem | None = None,
verbose: bool = False,
) -> dict[str, Any]
Optimize a parquet dataset through compaction and optional statistics recalculation.
This is a convenience function that combines compaction with optional statistics recalculation. It's particularly useful after many small write operations have created a large number of small files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset root directory |
required |
target_mb_per_file
|
int | None
|
Target size per file in MB |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec to use |
None
|
filesystem
|
AbstractFileSystem | None
|
Optional filesystem instance |
None
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Optimization statistics |
Example
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
fsspeckit.datasets.pyarrow.unify_schemas
¶
unify_schemas(
schemas: list[Schema],
standardize_timezones: bool = True,
verbose: bool = False,
) -> Schema
Unify multiple PyArrow schemas into a single schema.
This function handles type conflicts by: 1. Finding fields with conflicting types 2. Attempting to normalize compatible types 3. Using fallback strategies for incompatible types 4. Removing problematic fields if necessary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of schemas to unify |
required |
standardize_timezones
|
bool
|
Whether to standardize timezone info |
True
|
verbose
|
bool
|
Whether to print conflict information |
False
|
Returns:
| Type | Description |
|---|---|
Schema
|
Unified PyArrow schema |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schemas cannot be unified |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
fsspeckit.datasets.pyarrow_dataset
¶
PyArrow dataset operations including merge and maintenance helpers.
This module contains functions for dataset-level operations including: - Dataset merging with various strategies - Dataset statistics collection - Dataset compaction and optimization - Maintenance operations
Classes¶
Functions¶
fsspeckit.datasets.pyarrow_dataset.collect_dataset_stats_pyarrow
¶
collect_dataset_stats_pyarrow(
path: str,
filesystem: AbstractFileSystem | None = None,
partition_filter: list[str] | None = None,
) -> dict[str, Any]
Collect file-level statistics for a parquet dataset using shared core logic.
This function delegates to the shared fsspeckit.core.maintenance.collect_dataset_stats
function, ensuring consistent dataset discovery and statistics across both DuckDB
and PyArrow backends.
The helper walks the given dataset directory on the provided filesystem, discovers parquet files (recursively), and returns basic statistics:
- Per-file path, size in bytes, and number of rows
- Aggregated total bytes and total rows
The function is intentionally streaming/metadata-driven and never
materializes the full dataset as a single :class:pyarrow.Table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Root directory of the parquet dataset. |
required |
filesystem
|
AbstractFileSystem | None
|
Optional fsspec filesystem. If omitted, a local "file" filesystem is used. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefix filters
(e.g. ["date=2025-11-04"]). Only files whose path relative to
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist or no parquet files match the optional partition filter. |
Note
This is a thin wrapper around the shared core function. See
:func:fsspeckit.core.maintenance.collect_dataset_stats for the
authoritative implementation.
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
fsspeckit.datasets.pyarrow_dataset.compact_parquet_dataset_pyarrow
¶
compact_parquet_dataset_pyarrow(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
dry_run: bool = False,
filesystem: AbstractFileSystem | None = None,
) -> dict[str, Any]
Compact a parquet dataset directory into fewer larger files using PyArrow and shared planning.
Groups small files based on size (MB) and/or row thresholds, rewrites grouped files into new parquet files, and optionally changes compression. Supports a dry-run mode that returns the compaction plan without modifying files.
The implementation uses the shared core planning algorithm for consistent behavior across backends. It processes data in a group-based, streaming fashion: it reads only the files in a given group into memory when processing that group and never materializes the entire dataset as a single table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset root directory (local path or fsspec URL). |
required |
target_mb_per_file
|
int | None
|
Optional max output size per file; must be > 0. |
None
|
target_rows_per_file
|
int | None
|
Optional max rows per output file; must be > 0. |
None
|
partition_filter
|
list[str] | None
|
Optional list of partition prefixes (e.g. |
None
|
compression
|
str | None
|
Optional parquet compression codec; defaults to |
None
|
dry_run
|
bool
|
When |
False
|
filesystem
|
AbstractFileSystem | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A stats dictionary describing before/after file counts, total bytes, |
dict[str, Any]
|
rewritten bytes, and optional |
dict[str, Any]
|
The structure follows the canonical |
Raises:
| Type | Description |
|---|---|
ValueError
|
If thresholds are invalid or no files match partition filter. |
FileNotFoundError
|
If the path does not exist. |
Example
Note
This function delegates dataset discovery and compaction planning to the
shared fsspeckit.core.maintenance module, ensuring consistent behavior
across DuckDB and PyArrow backends.
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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 212 213 214 215 216 217 218 | |
fsspeckit.datasets.pyarrow_dataset.merge_parquet_dataset_pyarrow
¶
merge_parquet_dataset_pyarrow(
sources: list[str],
output_path: str,
target: str | None = None,
strategy: str | MergeStrategy = "deduplicate",
key_columns: list[str] | str | None = None,
filesystem: AbstractFileSystem | None = None,
compression: str | None = None,
row_group_size: int | None = 500000,
max_rows_per_file: int | None = 5000000,
verbose: bool = False,
**kwargs: Any,
) -> MergeStats
Merge multiple parquet datasets using PyArrow with various strategies.
This function provides dataset merging capabilities with support for: - Multiple merge strategies (upsert, insert, update, full_merge, deduplicate) - Key-based merging for relational operations - Batch processing for large datasets - Configurable output settings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
list[str]
|
List of source dataset paths |
required |
output_path
|
str
|
Path for merged output |
required |
target
|
str | None
|
Target dataset path (for upsert/update strategies) |
None
|
strategy
|
str | MergeStrategy
|
Merge strategy to use |
'deduplicate'
|
key_columns
|
list[str] | str | None
|
Key columns for merging (required for relational strategies) |
None
|
filesystem
|
AbstractFileSystem | None
|
fsspec filesystem instance |
None
|
compression
|
str | None
|
Output compression codec |
None
|
row_group_size
|
int | None
|
Rows per parquet row group |
500000
|
max_rows_per_file
|
int | None
|
Max rows per output file |
5000000
|
verbose
|
bool
|
Print progress information |
False
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
MergeStats
|
MergeStats with merge statistics |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required parameters are missing |
FileNotFoundError
|
If sources don't exist |
Example
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
fsspeckit.datasets.pyarrow_dataset.optimize_parquet_dataset_pyarrow
¶
optimize_parquet_dataset_pyarrow(
path: str,
target_mb_per_file: int | None = None,
target_rows_per_file: int | None = None,
partition_filter: list[str] | None = None,
compression: str | None = None,
filesystem: AbstractFileSystem | None = None,
verbose: bool = False,
) -> dict[str, Any]
Optimize a parquet dataset through compaction and optional statistics recalculation.
This is a convenience function that combines compaction with optional statistics recalculation. It's particularly useful after many small write operations have created a large number of small files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Dataset root directory |
required |
target_mb_per_file
|
int | None
|
Target size per file in MB |
None
|
target_rows_per_file
|
int | None
|
Target rows per file |
None
|
partition_filter
|
list[str] | None
|
Optional partition filters |
None
|
compression
|
str | None
|
Compression codec to use |
None
|
filesystem
|
AbstractFileSystem | None
|
Optional filesystem instance |
None
|
verbose
|
bool
|
Print progress information |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Optimization statistics |
Example
Source code in src/fsspeckit/datasets/pyarrow_dataset.py
fsspeckit.datasets.pyarrow_schema
¶
PyArrow schema utilities for type inference, unification, and optimization.
This module contains functions for working with PyArrow schemas including: - Schema unification across multiple tables - Type inference and optimization - Timezone handling - Schema casting
Classes¶
Functions¶
fsspeckit.datasets.pyarrow_schema.cast_schema
¶
Cast a PyArrow table to a target schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
Source table |
required |
schema
|
Schema
|
Target schema |
required |
Returns:
| Type | Description |
|---|---|
Table
|
Table cast to target schema |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.convert_large_types_to_normal
¶
Convert large types (like large_string) to normal types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
PyArrow schema |
required |
Returns:
| Type | Description |
|---|---|
Schema
|
Schema with large types converted |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.dominant_timezone_per_column
¶
Determine the dominant timezone for each column across schemas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of PyArrow schemas to analyze |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, str]
|
Mapping of column names to dominant timezone strings |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.opt_dtype
¶
Optimize dtypes in a PyArrow table based on data analysis.
This function analyzes the data in each column and attempts to downcast to more appropriate types (e.g., int64 -> int32, float64 -> float32, string -> int/bool where applicable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
PyArrow table to optimize |
required |
strict
|
bool
|
Whether to use strict type checking |
False
|
columns
|
list[str] | None
|
List of columns to optimize (None for all) |
None
|
Returns:
| Type | Description |
|---|---|
Table
|
Table with optimized dtypes |
Example
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.remove_empty_columns
¶
Remove empty columns from a PyArrow table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
PyArrow table |
required |
Returns:
| Type | Description |
|---|---|
Table
|
Table with empty columns removed |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.standardize_schema_timezones
¶
standardize_schema_timezones(
schemas: list[Schema],
standardize_timezones: bool = True,
) -> list[Schema]
Standardize timezone information across schemas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of schemas to standardize |
required |
standardize_timezones
|
bool
|
Whether to standardize timezones |
True
|
Returns:
| Type | Description |
|---|---|
list[Schema]
|
List of schemas with standardized timezones |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.standardize_schema_timezones_by_majority
¶
Standardize timezone information across schemas based on majority.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of schemas to standardize |
required |
Returns:
| Type | Description |
|---|---|
list[Schema]
|
List of schemas with standardized timezones |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
fsspeckit.datasets.pyarrow_schema.unify_schemas
¶
unify_schemas(
schemas: list[Schema],
standardize_timezones: bool = True,
verbose: bool = False,
) -> Schema
Unify multiple PyArrow schemas into a single schema.
This function handles type conflicts by: 1. Finding fields with conflicting types 2. Attempting to normalize compatible types 3. Using fallback strategies for incompatible types 4. Removing problematic fields if necessary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of schemas to unify |
required |
standardize_timezones
|
bool
|
Whether to standardize timezone info |
True
|
verbose
|
bool
|
Whether to print conflict information |
False
|
Returns:
| Type | Description |
|---|---|
Schema
|
Unified PyArrow schema |
Raises:
| Type | Description |
|---|---|
ValueError
|
If schemas cannot be unified |
Source code in src/fsspeckit/datasets/pyarrow_schema.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |