Implementation:AI Northstar Tech Vector io Get Parquet Files
| Knowledge Sources | |
|---|---|
| Domains | Parquet, Data_Loading, HuggingFace |
| Last Updated | 2026-10-15 00:00 GMT |
Overview
Concrete utility functions for discovering and loading parquet files from local disk or HuggingFace Hub, provided by the vector-io library.
Description
The get_parquet_files and read_parquet_progress functions handle parquet file discovery and loading across multiple data sources. They support three data source modes:
- Local directory: Recursively walks the directory tree to find all *.parquet files.
- Local single file: Returns the file path directly if it ends with .parquet.
- HuggingFace Hub: Uses HfFileSystem to glob parquet files from a HuggingFace dataset, or streams via load_dataset with max_num_rows subsetting. Downloaded files are saved as temporary parquet files for local processing.
read_parquet_progress reads a single parquet file into a pandas DataFrame with progress indication. It supports:
- HuggingFace paths (hf:// prefix): Resolves the path via HfFileSystem and downloads via hf_hub_download.
- Column validation: Checks if requested columns exist in the parquet schema before reading.
- Row limiting: When max_num_rows is set, reads only the first N rows via ParquetFile.iter_batches.
- Progress spinner: Uses Halo to show loading progress.
Usage
Import these functions when you need to discover parquet files in a VDF dataset directory or load parquet files into DataFrames. Used primarily by ImportVDB subclasses during the import pipeline.
Code Reference
Source Location
- Repository: vector-io
- File: src/vdf_io/util.py
Signature
def get_parquet_files(
data_path: str,
args: dict,
temp_file_paths: list = [],
id_column: str = ID_COLUMN,
) -> List[str]:
"""
Discover parquet files in a local directory or HuggingFace Hub dataset.
For HuggingFace with max_num_rows: streams via load_dataset, converts to
parquet temp files. For HuggingFace without max_num_rows: globs via HfFileSystem.
For local directories: recursively walks to find *.parquet files.
For single .parquet files: returns [data_path].
Args:
data_path: Directory path or .parquet file path
args: CLI args dict (uses 'hf_dataset', 'max_num_rows', 'hash_value')
temp_file_paths: List to append downloaded temp file paths to
id_column: ID column name (used for HuggingFace subset validation)
Returns:
List of parquet file paths (local paths or hf:// URIs).
"""
def read_parquet_progress(
file_path: str,
id_column: str,
**kwargs,
) -> pd.DataFrame:
"""
Read a parquet file into a pandas DataFrame with progress indication.
Handles HuggingFace paths (hf:// prefix) by resolving and downloading.
Validates requested columns against the parquet schema.
Supports row limiting via max_num_rows kwarg.
Args:
file_path: Local path or hf:// URI
id_column: ID column name (always included in read)
**kwargs: Optional 'columns' (list) and 'max_num_rows' (int)
Returns:
pandas DataFrame with parquet data.
"""
Import
from vdf_io.util import get_parquet_files, read_parquet_progress
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data_path | str | Yes | Directory or .parquet file path |
| args | dict | Yes (get_parquet_files) | CLI args with 'hf_dataset', 'max_num_rows' |
| temp_file_paths | list | No | List to append temp file paths (mutated) |
| id_column | str | No | ID column name (default: ID_COLUMN) |
| file_path | str | Yes (read_parquet_progress) | Local path or hf:// URI |
| columns | list | No (kwargs) | Columns to read (validates against schema) |
| max_num_rows | int | No (kwargs) | Max rows to read (uses ParquetFile.iter_batches) |
Outputs
| Name | Type | Description |
|---|---|---|
| get_parquet_files returns | List[str] | Parquet file paths |
| read_parquet_progress returns | pd.DataFrame | Loaded parquet data |
| temp_file_paths | list (mutated) | Appended with downloaded temp file paths |
Usage Examples
Loading from Local Directory
from vdf_io.util import get_parquet_files, read_parquet_progress
# Discover parquet files in a VDF directory
parquet_files = get_parquet_files(
"./vdf_20240125_130746_ac5a6/my_index",
args={},
id_column="id",
)
# Returns: ["./vdf_20240125_130746_ac5a6/my_index/1.parquet", ...]
# Read each file into a DataFrame
for file in parquet_files:
df = read_parquet_progress(file, id_column="id")
print(f"Loaded {len(df)} rows from {file}")
Loading from HuggingFace Hub
# Discover parquet files in a HuggingFace dataset
args = {"hf_dataset": "aintech/vdf_20240125_130746_ac5a6_medium_articles"}
temp_files = []
parquet_files = get_parquet_files(
".",
args=args,
temp_file_paths=temp_files,
id_column="id",
)
# Returns: ["hf://datasets/aintech/.../1.parquet", ...]
# Load a single file (downloaded and cached via hf_hub_download)
df = read_parquet_progress(parquet_files[0], id_column="id")
Loading a Subset with max_num_rows
# Read only the first 1000 rows of a parquet file
df = read_parquet_progress(
"./data/vectors.parquet",
id_column="id",
max_num_rows=1000,
)
print(f"Loaded {len(df)} rows (requested max 1000)")
Reading Specific Columns
# Read only the vector column (plus id_column which is always included)
df = read_parquet_progress(
"./data/vectors.parquet",
id_column="id",
columns=["vector"],
)
# If 'vector' column doesn't exist, returns empty DataFrame