Merge pull request #3823 from lonvia/fix-postcode-difference

Fix difference computation on postcode updates
This commit is contained in:
Sarah Hoffmann
2025-08-29 17:06:08 +02:00
committed by GitHub
2 changed files with 7 additions and 5 deletions

View File

@@ -119,7 +119,7 @@ class _PostcodeCollector:
pcobj = self.collected.pop(postcode, None)
if pcobj:
newx, newy = pcobj.centroid()
if (x - newx) > 0.0000001 or (y - newy) > 0.0000001:
if abs(x - newx) > 0.0000001 or abs(y - newy) > 0.0000001:
to_update.append((newx, newy, postcode))
else:
to_delete.append(postcode)

View File

@@ -100,10 +100,12 @@ def test_postcodes_add_new(dsn, postcode_table, insert_implicit_postcode, tokeni
assert postcode_table.row_set == {('xx', '9486', 10, 12), }
@pytest.mark.parametrize('coords', [(99, 34), (10, 34), (99, 12),
(9, 34), (9, 11), (23, 11)])
def test_postcodes_replace_coordinates(dsn, postcode_table, tmp_path,
insert_implicit_postcode, tokenizer):
insert_implicit_postcode, tokenizer, coords):
insert_implicit_postcode(1, 'xx', 'POINT(10 12)', dict(postcode='AB 4511'))
postcode_table.add('xx', 'AB 4511', 99, 34)
postcode_table.add('xx', 'AB 4511', *coords)
postcodes.update_postcodes(dsn, tmp_path, tokenizer)
@@ -113,11 +115,11 @@ def test_postcodes_replace_coordinates(dsn, postcode_table, tmp_path,
def test_postcodes_replace_coordinates_close(dsn, postcode_table,
insert_implicit_postcode, tokenizer):
insert_implicit_postcode(1, 'xx', 'POINT(10 12)', dict(postcode='AB 4511'))
postcode_table.add('xx', 'AB 4511', 10, 11.99999)
postcode_table.add('xx', 'AB 4511', 10, 11.99999999)
postcodes.update_postcodes(dsn, None, tokenizer)
assert postcode_table.row_set == {('xx', 'AB 4511', 10, 11.99999)}
assert postcode_table.row_set == {('xx', 'AB 4511', 10, 11.99999999)}
def test_postcodes_remove(dsn, postcode_table,