Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
fix regression found on postcode
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinL committed Jun 5, 2020
1 parent c77f1e4 commit ad2132b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions splink_data_normalisation/postcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def postcode_to_inward_outward(df: DataFrame, pc_field: str, drop_orig:bool = Tr

# If the postcode is long enough, parse out inner outer
# If it's too short, assume we only have the outer part

sql = """
case
when length(pc_nospace_temp__) >= 6 then left(pc_nospace_temp__, length(pc_nospace_temp__) - 3)
when length(pc_nospace_temp__) >= 5 then left(pc_nospace_temp__, length(pc_nospace_temp__) - 3)
else left(pc_nospace_temp__, 4)
end
"""
Expand All @@ -32,7 +32,7 @@ def postcode_to_inward_outward(df: DataFrame, pc_field: str, drop_orig:bool = Tr

sql = """
case
when length(pc_nospace_temp__) >= 6 then right(pc_nospace_temp__, 3)
when length(pc_nospace_temp__) >= 5 then right(pc_nospace_temp__, 3)
else null
end
"""
Expand Down
8 changes: 7 additions & 1 deletion tests/test_postcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def test_pc_1(spark):
{"id": 8, "postcode": "AB12C"},
{"id": 9, "postcode": "AB12"},
{"id": 10, "postcode": "AB1"},
{"id": 11, "postcode": "B8 3QF"},
{"id": 12, "postcode": "B83QF"},


]

df = spark.createDataFrame(Row(**x) for x in postcode_list)
Expand All @@ -33,9 +37,11 @@ def test_pc_1(spark):
{"id": 5, "outward_postcode_norm": "AB1C", "inward_postcode_norm": "2DE"},
{"id": 6, "outward_postcode_norm": "AB1C", "inward_postcode_norm": "2DE"},
{"id": 7, "outward_postcode_norm": "AB1", "inward_postcode_norm": "2CD"},
{"id": 8, "outward_postcode_norm": "AB12", "inward_postcode_norm": None},
{"id": 8, "outward_postcode_norm": "AB", "inward_postcode_norm": "12C"},
{"id": 9, "outward_postcode_norm": "AB12", "inward_postcode_norm": None},
{"id": 10, "outward_postcode_norm": "AB1", "inward_postcode_norm": None},
{"id": 11, "outward_postcode_norm": "B8", "inward_postcode_norm": "3QF"},
{"id": 12, "outward_postcode_norm": "B8", "inward_postcode_norm": "3QF"},

]

Expand Down

0 comments on commit ad2132b

Please sign in to comment.