Hash
matchlab.core.hash
¶
Utilities for hashing data and creating unique identifiers.
Classes:
-
HashMethod–Supported hash methods for row hashing.
Functions:
-
hash_rows–Hash each row of
dfovercolumns. -
hash_dataframe–Content-address
dfwith a hash invariant to row and column order.
Attributes:
HashMethod
¶
Bases: StrEnum
flowchart TD
matchlab.core.hash.HashMethod[HashMethod]
click matchlab.core.hash.HashMethod href "" "matchlab.core.hash.HashMethod"
Supported hash methods for row hashing.
Attributes:
hash_rows
¶
hash_rows(df: DataFrame, columns: list[str], method: HashMethod = XXH3_128) -> Series
Hash each row of df over columns.
Each row's hash covers both column names and values, joined with the record and
unit separator symbols (␞, ␟), so a column's name is part of what gets hashed
alongside its value.
hash_dataframe
¶
hash_dataframe(df: DataFrame, method: HashMethod = XXH3_128, as_sorted_list: list[str] | None = None) -> bytes
Content-address df with a hash invariant to row and column order.
Pass as_sorted_list (2 or more column names, e.g. ["left_id", "right_id"]) to
hash those columns as a sorted set instead of individually, so (1, 2) and
(2, 1) hash the same. This replaces the named columns with one sorted_list
column.
Combining as_sorted_list with a nullable column can null the whole row's hash
input, because Polars' concat_list returns null when any input is null.
Raises:
-
ValueError–If
as_sorted_listnames fewer than two columns, or a columndfdoesn't have.