Skip to content

Commit

Permalink
Merge pull request #69 from openaddresses/fix-first-non-empty
Browse files Browse the repository at this point in the history
Fix output generation to handle edge case in first-non-empty function
  • Loading branch information
iandees authored Nov 23, 2024
2 parents 330bde4 + 90677e1 commit 76e4605
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openaddr/conform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,10 @@ def row_convert_to_out(source_config, row):
# Get a native field as specified in the conform object
cfield = source_config.data_source['conform'].get(field)

if cfield:
# If the field is a string, it is a direct mapping to the source
# It might not be a string if it's a function that failed to
# resolve to an oa:-prefixed field.
if cfield and isinstance(cfield, str):
output["properties"][field] = row.get(cfield)
else:
output["properties"][field] = ''
Expand Down
38 changes: 38 additions & 0 deletions openaddr/tests/conform.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,44 @@ def test_transform_and_convert(self):
}
}, r)

"Test first_non_empty function with nothing found"
d = SourceConfig(dict({
"schema": 2,
"layers": {
"addresses": [{
"name": "default",
"conform": {
"number": {
"function": "first_non_empty",
"fields": ["a", "b"]
},
"lon": "y",
"lat": "x",
},
"fingerprint": "0000"
}]
}
}), "addresses", "default")
r = row_transform_and_convert(d, { "a": "", "b": "", GEOM_FIELDNAME: "POINT(-119.2 39.3)" })
self.assertEqual({
'type': 'Feature',
'geometry': {
"type": "Point",
"coordinates": [-119.2, 39.3]
},
'properties': {
"street": "",
"unit": "",
"number": "",
"city": "",
"region": "",
"district": "",
"postcode": "",
"id": "",
'hash': '7b1dc0b74cbc0162'
}
}, r)

def test_row_canonicalize_unit_and_number(self):
r = row_canonicalize_unit_and_number({}, {"number": "324 ", "street": " OAK DR.", "unit": "1"})
self.assertEqual("324", r["number"])
Expand Down

0 comments on commit 76e4605

Please sign in to comment.