Core API Reference¶
Complete API reference for ParquetFrame core functionality.
Core Classes¶
ParquetFrame¶
The main class for working with parquet data.
parquetframe.ParquetFrame
¶
A wrapper for pandas and Dask DataFrames to simplify working with parquet files.
The class automatically switches between pandas and Dask based on file size or a manual flag. It delegates all standard DataFrame methods to the active internal dataframe.
Examples:
>>> import parquetframe as pqf
>>> # Read file with automatic backend selection
>>> pf = pqf.pf.read("data.parquet")
>>> # Manual backend control
>>> pf = pqf.pf.read("data", islazy=True) # Force Dask
>>> # Standard DataFrame operations work transparently
>>> result = pf.groupby("column").sum()
Source code in src/parquetframe/core.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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 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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 491 492 493 494 495 496 497 498 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 |
|
islazy
property
writable
¶
Get the current backend type (True for Dask, False for pandas).
bio
property
¶
Access bioframe functions with intelligent parallel dispatching.
Returns BioAccessor that automatically chooses between pandas (eager) and Dask (parallel) implementations based on the current backend.
Returns:
Type | Description |
---|---|
BioAccessor instance for genomic operations. |
Raises:
Type | Description |
---|---|
ImportError
|
If bioframe is not installed. |
Examples:
__init__(df=None, islazy=False, track_history=False)
¶
Initialize the ParquetFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
Optional[Union[DataFrame, DataFrame]]
|
An initial dataframe (pandas or Dask). |
None
|
islazy
|
bool
|
If True, forces a Dask DataFrame. |
False
|
track_history
|
bool
|
If True, enables history tracking for CLI sessions. |
False
|
Source code in src/parquetframe/core.py
__repr__()
¶
String representation of the object.
Source code in src/parquetframe/core.py
__getitem__(key)
¶
Support indexing operations (df[column] or df[columns]).
Source code in src/parquetframe/core.py
__len__()
¶
__getattr__(name)
¶
Delegate attribute access to the underlying dataframe.
This method is called for attributes not found in the ParquetFrame instance. It forwards the call to the internal dataframe (_df).
Source code in src/parquetframe/core.py
read(file, threshold_mb=None, islazy=None, **kwargs)
classmethod
¶
Read a parquet file into a ParquetFrame.
Automatically selects pandas or Dask based on file size, unless overridden. Handles file extension detection automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Union[str, Path]
|
Path to the parquet file (extension optional). |
required |
threshold_mb
|
Optional[float]
|
Size threshold in MB for backend selection. Defaults to 10MB. |
None
|
islazy
|
Optional[bool]
|
Force backend selection (True=Dask, False=pandas, None=auto). |
None
|
**kwargs
|
Additional keyword arguments for read_parquet methods. |
{}
|
Returns:
Type | Description |
---|---|
ParquetFrame
|
ParquetFrame instance with loaded data. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If no parquet file is found. |
Examples:
>>> pf = ParquetFrame.read("data") # Auto-detects .parquet/.pqt
>>> pf = ParquetFrame.read("data.parquet", threshold_mb=50)
>>> pf = ParquetFrame.read("data", islazy=True) # Force Dask
Source code in src/parquetframe/core.py
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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
save(file, save_script=None, **kwargs)
¶
Save the dataframe to a parquet file.
Automatically adds .parquet extension if not present. Works with both pandas and Dask dataframes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Union[str, Path]
|
Base name for the output file. |
required |
save_script
|
Optional[str]
|
If provided, saves session history to this Python script. |
None
|
**kwargs
|
Additional keyword arguments for to_parquet methods. |
{}
|
Returns:
Type | Description |
---|---|
ParquetFrame
|
Self for method chaining. |
Raises:
Type | Description |
---|---|
TypeError
|
If no dataframe is loaded. |
Examples:
>>> pf.save("output") # Saves as output.parquet
>>> pf.save("data.parquet", compression='snappy')
>>> pf.save("output", save_script="session.py") # Also saves session history
Source code in src/parquetframe/core.py
to_pandas()
¶
Convert the internal Dask dataframe to a pandas dataframe.
Returns:
Type | Description |
---|---|
ParquetFrame
|
Self for method chaining. |
Source code in src/parquetframe/core.py
to_dask(npartitions=None)
¶
Convert the internal pandas dataframe to a Dask dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
npartitions
|
Optional[int]
|
Number of partitions for the Dask dataframe. Defaults to the number of CPU cores. |
None
|
Returns:
Type | Description |
---|---|
ParquetFrame
|
Self for method chaining. |
Source code in src/parquetframe/core.py
sql(query, **other_frames)
¶
Execute a SQL query on this ParquetFrame using DuckDB.
The current ParquetFrame is available as 'df' in the query. Additional ParquetFrames can be passed as keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
SQL query string to execute. |
required |
**other_frames
|
ParquetFrame
|
Additional ParquetFrames to use in JOINs. |
{}
|
Returns:
Type | Description |
---|---|
ParquetFrame
|
New ParquetFrame with query results (always pandas backend). |
Raises:
Type | Description |
---|---|
ImportError
|
If DuckDB is not installed. |
ValueError
|
If query execution fails. |
Examples:
>>> # Simple query
>>> result = pf.sql("SELECT * FROM df WHERE age > 25")
>>>
>>> # JOIN with another ParquetFrame
>>> orders = pf.sql(
... "SELECT * FROM df JOIN customers ON df.cust_id = customers.id",
... customers=customers_pf
... )
Source code in src/parquetframe/core.py
get_history()
¶
Get the current session history.
Returns:
Type | Description |
---|---|
Optional[list]
|
List of command strings if history tracking is enabled, None otherwise. |
clear_history()
¶
Core Functions¶
Reading Data¶
Functions for loading data from various sources.
parquetframe.read(file, threshold_mb=None, islazy=None, **kwargs)
¶
Read a parquet file into a ParquetFrame.
This is a convenience function that wraps ParquetFrame.read().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Union[str, Path]
|
Path to the parquet file (extension optional). |
required |
threshold_mb
|
Optional[float]
|
Size threshold in MB for backend selection. Defaults to 10MB. |
None
|
islazy
|
Optional[bool]
|
Force backend selection (True=Dask, False=pandas, None=auto). |
None
|
**kwargs
|
Additional keyword arguments for read_parquet methods. |
{}
|
Returns:
Type | Description |
---|---|
ParquetFrame
|
ParquetFrame instance with loaded data. |
Examples:
>>> import parquetframe as pqf
>>> df = pqf.read("data") # Auto-detect extension and backend
>>> df = pqf.read("data.parquet", threshold_mb=50)
>>> df = pqf.read("data", islazy=True) # Force Dask
Source code in src/parquetframe/__init__.py
Writing Data¶
Functions for saving data to various formats.
parquetframe.ParquetFrame.save(file, save_script=None, **kwargs)
¶
Save the dataframe to a parquet file.
Automatically adds .parquet extension if not present. Works with both pandas and Dask dataframes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Union[str, Path]
|
Base name for the output file. |
required |
save_script
|
Optional[str]
|
If provided, saves session history to this Python script. |
None
|
**kwargs
|
Additional keyword arguments for to_parquet methods. |
{}
|
Returns:
Type | Description |
---|---|
ParquetFrame
|
Self for method chaining. |
Raises:
Type | Description |
---|---|
TypeError
|
If no dataframe is loaded. |
Examples:
>>> pf.save("output") # Saves as output.parquet
>>> pf.save("data.parquet", compression='snappy')
>>> pf.save("output", save_script="session.py") # Also saves session history
Source code in src/parquetframe/core.py
Data Processing¶
Filtering and Selection¶
Methods for filtering and selecting data.
Aggregation¶
Methods for data aggregation and grouping.
Transformation¶
Methods for data transformation and feature engineering.
Summary¶
The core API provides comprehensive functionality for data loading, processing, and saving with optimal performance.
Examples¶
import parquetframe as pf
# Create ParquetFrame instance
df = pf.ParquetFrame()
# Load data
df = pf.read("data.parquet")
# Process data
filtered = df.filter("column > 100")
grouped = df.groupby("category").sum()
# Save results
df.save("output.parquet")