uuidhash — UUID v5¶
Deterministic UUID version 5, on pl.Expr as .uuidhash.
A v5 UUID is a SHA-1 digest of a namespace UUID and a name, in UUID format. The result is deterministic: the same namespace and the same name always give the same UUID, so a v5 UUID is a key for a value you have. A null input gives a null output.
uuid5
¶
uuid5(namespace: UUIDNamespace | str = DNS) -> Expr
Make a UUID v5 from a Utf8 or Binary column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
UUIDNamespace | str
|
A standard namespace:
|
DNS
|
Returns:
| Type | Description |
|---|---|
Expr
|
Utf8, the 36-character format with hyphens. |
Raises:
| Type | Description |
|---|---|
ComputeError
|
|
Examples:
>>> df = pl.DataFrame({"literal": ["hello", None, "world"]})
>>> df.select(plh.col("literal").uuidhash.uuid5()).to_series().to_list()
['9342d47a-1bab-5709-9869-c840b2eac501', None, 'b3a4c24e-f57a-5448-b81b-a643f6768036']
A custom namespace:
uuid5_concat
¶
Concatenate two Utf8 columns and make a UUID v5 in the DNS namespace.
Use this to make a key from two columns with one expression, in place of
a concat_str and a uuid5.
The two columns are not equivalent. A null in the first column gives
null. A null in other gives the UUID of the first value and default,
or of the first value alone when default is None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Expr
|
The second column, which polars-hash puts after the first. It
must be Utf8, and polars-hash casts it to Utf8 first if you set
|
required |
default
|
str | None
|
The value that replaces a null in |
None
|
Returns:
| Type | Description |
|---|---|
Expr
|
Utf8. |
Raises:
| Type | Description |
|---|---|
ComputeError
|
|
Note
This expression adds no separator, so ("ab", "c") and ("a", "bc")
give the same UUID. If your data can have this condition, make the
key with a separator that the data does not contain, with
concat_str:
plh.concat_str("id", "side", separator="|").uuidhash.uuid5(). That
form also lets you select the namespace.
Examples:
>>> df = pl.DataFrame({"id": ["abc-123"], "side": ["a"]})
>>> df.select(plh.col("id").uuidhash.uuid5_concat(pl.col("side"))).item()
'e89d330c-f123-519c-a7a1-e48e46f30ccf'
default gives a null in other the same result as the value
itself:
UUIDNamespace
¶
Bases: str, Enum
The four RFC 4122 namespaces for a UUID v5.
This is a str enum, so a member and its value are equivalent arguments.
DNS names a fully qualified domain name, URL a URL, OID an ISO object
identifier, and X500 an X.500 distinguished name.
Examples:
>>> df = pl.DataFrame({"foo": ["https://example.com"]})
>>> df.select(plh.col("foo").uuidhash.uuid5(plh.UUIDNamespace.URL)).item()
'4fd35a71-71ef-5a55-a9d9-aa75c889a6d0'
>>> df.select(plh.col("foo").uuidhash.uuid5("url")).item()
'4fd35a71-71ef-5a55-a9d9-aa75c889a6d0'