Skip to content

pudl_diff.row_counts

Comparing the row counts of two tables.

RowCountDiff dataclass

The row counts of two tables.

Source code in src/pudl_diff/row_counts.py
@dataclass(frozen=True)
class RowCountDiff:
    """The row counts of two tables."""

    left_row_count: int
    """Row count of the left table."""
    right_row_count: int
    """Row count of the right table."""

    @property
    def is_identical(self) -> bool:
        """Whether the tables have the same number of rows."""
        return self.left_row_count == self.right_row_count

is_identical property

Whether the tables have the same number of rows.

left_row_count instance-attribute

Row count of the left table.

right_row_count instance-attribute

Row count of the right table.

compare_row_counts(left, right)

Compare the row counts of two tables.

Parameters:

Name Type Description Default
left LazyFrame

The "left" table to compare.

required
right LazyFrame

The "right" table to compare against left.

required
Source code in src/pudl_diff/row_counts.py
def compare_row_counts(left: pl.LazyFrame, right: pl.LazyFrame) -> RowCountDiff:
    """Compare the row counts of two tables.

    Args:
        left: The "left" table to compare.
        right: The "right" table to compare against `left`.
    """
    return RowCountDiff(
        left_row_count=count_rows(left), right_row_count=count_rows(right)
    )

count_rows(lf)

Count the rows of lf, streaming so that it needn't fit in memory.

Source code in src/pudl_diff/row_counts.py
def count_rows(lf: pl.LazyFrame) -> int:
    """Count the rows of `lf`, streaming so that it needn't fit in memory."""
    return lf.select(pl.len()).collect(engine="streaming").item()