Skip to content

Commit

Permalink
Merge pull request #2452 from moj-analytical-services/2440-add-docstr…
Browse files Browse the repository at this point in the history
…ing-to-customrule

2440 add docstring to customrule
  • Loading branch information
RobinL authored Oct 5, 2024
2 parents 57cef10 + ab5c1c3 commit cb39830
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/api_docs/blocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ tags:
- API
- blocking
---
# Documentation for`block_on`
# Documentation for the `blocking_rule_library`

::: splink.block_on
::: splink.blocking_rule_library
handler: python
options:
show_root_heading: false
show_root_toc: false
show_source: false
members_order: source
inherited_members: false
merge_init_into_class: true



Expand Down
13 changes: 13 additions & 0 deletions splink/blocking_rule_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from splink.internals.blocking_rule_library import (
And,
CustomRule,
Not,
block_on,
)

__all__ = [
"CustomRule",
"And",
"Not",
"block_on",
]
37 changes: 37 additions & 0 deletions splink/internals/blocking_rule_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,43 @@ def __init__(
salting_partitions: int | None = None,
arrays_to_explode: list[str] | None = None,
):
"""
Represents a custom blocking rule using a user-defined SQL condition. To
refer to the left hand side and the right hand side of the pairwise
record comparison, use `l` and `r` respectively, e.g.
`l.first_name = r.first_name and len(l.first_name) <2`.
Args:
blocking_rule (str): A SQL condition string representing the custom
blocking rule.
sql_dialect (str, optional): The SQL dialect of the provided blocking rule.
If specified, Splink will attempt to translate the rule to the
appropriate dialect.
salting_partitions (int, optional): The number of partitions to use for
salting. If provided, enables salting for this blocking rule.
arrays_to_explode (list[str], optional): A list of array column names
to explode before applying the blocking rule.
Examples:
```python
from splink.blocking_rule_library import CustomRule
# Simple custom rule
rule_1 = CustomRule("l.postcode = r.postcode")
# Custom rule with dialect translation
rule_2 = CustomRule(
"SUBSTR(l.surname, 1, 3) = SUBSTR(r.surname, 1, 3)",
sql_dialect="sqlite"
)
# Custom rule with salting
rule_3 = CustomRule(
"l.city = r.city",
salting_partitions=10
)
```
"""
super().__init__(
salting_partitions=salting_partitions, arrays_to_explode=arrays_to_explode
)
Expand Down

0 comments on commit cb39830

Please sign in to comment.