Agent skills for Liken: near-deduplication and record linkage for Python DataFrames.
78
98%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
When no built-in deduper expresses your rule, write one. A custom deduper is a plain
Python function, registered with @lk.custom.register, that Liken then treats like any
other deduper. Always import liken as lk. Targets liken >= 0.8.
A custom deduper function:
array (an iterable standing in for one column) as its
first argument, plus keyword-only parameters: def f(array, *, **kwargs);(i, j) index pairs for records that should be linked (a generator is
preferred over building and returning a list);import liken as lk
@lk.custom.register
def str_same_len(array, *, min_len: int):
n = len(array)
for i in range(n):
for j in range(i + 1, n):
if len(array[i]) == len(array[j]) and len(array[i]) > min_len:
yield i, jYou never pass array yourself — Liken builds it from the column you target. The
decorator enforces keyword-only arguments at call time (str_same_len(12) raises
TypeError; str_same_len(min_len=12) is correct).
import liken as lk
# Single deduper — column in drop_duplicates
df = lk.dedupe(df).apply(str_same_len(min_len=12)).drop_duplicates("address")
# Dict collection — column is the key
df = lk.dedupe(df).apply({"address": str_same_len(min_len=12)}).drop_duplicates()
# Pipeline — registered name is available as an lk.col() method
df = (
lk.dedupe(df)
.apply(lk.pipeline().step(lk.col("address").str_same_len(min_len=12)))
.drop_duplicates()
)In a pipeline a custom deduper can be AND-combined with built-ins inside a .step([...])
— see liken-pipelines.
TypeError. Define them after *.~ negation. Custom dedupers cannot be inverted with ~. Register a separate
function for the inverse (e.g. not_str_same_len) that yields the complementary pairs.array may contain None (and non-string
values), so len(array[i]) can raise. Skip them explicitly, e.g.
if array[i] is None or array[j] is None: continue before comparing.