Principle:AI Northstar Tech Vector io Parquet Discovery Loading
| Knowledge Sources | |
|---|---|
| Domains | Parquet, Data_Loading, HuggingFace |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
A data loading pattern that discovers parquet files from multiple sources (local disk or HuggingFace Hub) and loads them into DataFrames with column validation, row limiting, and progress indication.
Description
Parquet Discovery and Loading addresses the challenge of locating and reading parquet files across heterogeneous storage backends. A VDF dataset may be stored locally as a directory of parquet files, or remotely on the HuggingFace Hub as a dataset repository.
The pattern supports three data source modes:
- Local directory: Recursively walks the directory tree using os.walk to find all *.parquet files. This is the simplest case and the default for local VDF datasets.
- Local single file: If the path directly ends with .parquet, returns it as a single-element list.
- HuggingFace Hub: Uses HfFileSystem to glob parquet files from a HuggingFace dataset repository. When max_num_rows is set, streams via load_dataset with subsetting, converting the result to temporary local parquet files for uniform downstream processing.
When loading individual parquet files, the pattern validates that requested columns exist in the parquet schema before reading, returning an empty DataFrame if columns are missing. This prevents runtime errors during import when parquet schemas vary slightly across files.
Row limiting via max_num_rows uses ParquetFile.iter_batches for efficient partial reads, avoiding loading the entire file into memory.
Usage
Use this principle when designing systems that need to load parquet files from local or remote sources. It is suited for:
- Import tools that read VDF datasets from disk or HuggingFace
- Data pipeline tools that need to handle multiple storage backends
- Systems where parquet file schemas may vary and need validation before loading
Theoretical Basis
The discovery and loading flow:
# Abstract algorithm (NOT real implementation)
def get_parquet_files(data_path, args):
if args.get("hf_dataset"):
if args.get("max_num_rows"):
# Stream via load_dataset, save as temp parquet files
return stream_and_save_temp(args["hf_dataset"], args["max_num_rows"])
else:
# Glob via HuggingFace file system
return hf_glob(f"datasets/{args['hf_dataset']}/{data_path}/**/*.parquet")
elif os.path.isdir(data_path):
# Walk directory tree
return [f for f in os.walk(data_path) if f.endswith(".parquet")]
elif data_path.endswith(".parquet"):
return [data_path]
def read_parquet_progress(file_path, id_column, **kwargs):
# Validate columns against schema
schema = pq.read_schema(file_path)
if "columns" in kwargs:
missing = [c for c in kwargs["columns"] if c not in schema.names]
if missing:
return empty_dataframe()
# Read with optional row limit
if kwargs.get("max_num_rows"):
return read_first_n_rows(file_path, kwargs["max_num_rows"])
else:
return pd.read_parquet(file_path)