pudl_diff.rows
¶
Comparing the rows of two tables, with or without a primary key.
MAX_ROWS_PER_PARTITION = 100000000
module-attribute
¶
Tables with more rows than this have their key hashes reduced and joined in several partitions, one after the other, to bound the memory the comparison needs. At around 75 bytes of peak memory per row, 100 million rows is roughly 8 GB.
KeyedRowDiff
dataclass
¶
Row-level differences between two tables that share a primary key.
Like RowSetDiff, the differing rows are backed by temporary Parquet
files (owned by pk_diff) rather than held in memory.
Source code in src/pudl_diff/rows.py
changed_left
instance-attribute
¶
Rows sharing a primary key whose non-primary-key values differ, holding the left table's values, with the same schema as the left table.
changed_right
instance-attribute
¶
Same as changed_left, but holding the right table's values
for those same primary keys, with the same schema as the right table.
changed_row_count
instance-attribute
¶
Number of shared-primary-key rows with at least one differing non-primary-key value.
column_changes
instance-attribute
¶
Maps each non-primary-key column to the number of shared-primary-key rows where its value differs between the two tables. Columns with no changes are omitted.
is_identical
property
¶
Whether every shared-key row matches and no keys are one-sided.
pk_diff
instance-attribute
¶
Symmetric difference of primary key values: full rows present in only one of the two tables.
RowSetDiff
dataclass
¶
The multiset symmetric difference of rows between two tables.
A row only counts as "the same" if the key columns match on both sides -
every column, for tables with no primary key, or just the primary key columns,
for tables that have one. For tables with no primary key, the number of
copies of each row matters too: a row appearing 3 times on the left and once
on the right contributes 2 rows to only_in_left.
The differing rows themselves are backed by temporary Parquet files, so they
can be far larger than memory. The files are deleted by cleanup(), or else
when this object (and any other object sharing spill_dir) is garbage
collected; call .collect() on a frame to load it.
Source code in src/pudl_diff/rows.py
SpillDir
¶
A temporary directory holding the Parquet files of a comparison's rows.
Unlike tempfile.TemporaryDirectory, it is not a mistake to leave it to be
cleaned up implicitly, so doing so doesn't warn: it is removed when
cleanup() is called, or else when this object is garbage collected or the
interpreter exits, whichever comes first.
Source code in src/pudl_diff/rows.py
__init__()
¶
compare_rows_with_pk(left, right, pk_cols, *, rtol=1e-05, atol=1e-08)
¶
Compare two tables sharing a primary key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
LazyFrame
|
The "left" table to compare. Must have the same columns as
|
required |
right
|
LazyFrame
|
The "right" table to compare against |
required |
pk_cols
|
Sequence[str]
|
Names of the primary key columns shared by both tables, e.g.
from |
required |
rtol
|
float
|
Relative tolerance used to treat two floating point values as
equal, matching |
1e-05
|
atol
|
float
|
Absolute tolerance used to treat two floating point values as
equal, matching |
1e-08
|
Source code in src/pudl_diff/rows.py
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 | |
compare_rows_without_pk(left, right, *, rtol=1e-05, atol=1e-08)
¶
Compare two tables with no primary key by taking the symmetric difference of rows.
The comparison is of multisets: a row that appears a different number of times in the two tables counts as a difference, and the surplus copies are reported as only in the table that has more of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
LazyFrame
|
The "left" table to compare. Must have the same columns as
|
required |
right
|
LazyFrame
|
The "right" table to compare against |
required |
rtol
|
float
|
Relative tolerance used to treat two floating point values as
equal, matching |
1e-05
|
atol
|
float
|
Absolute tolerance used to treat two floating point values as
equal, matching |
1e-08
|
Raises:
| Type | Description |
|---|---|
SchemaError
|
if a column's dtype differs between
|