Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw results in geocode_table, too #42

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions geocode_sqlite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def geocode_table(
log.info(f"Adding longitude column: {longitude_column}")
table.add_column(longitude_column, float)

if raw and raw != "raw":
log.info(f"Using custom raw result field: {raw}")

if raw and raw not in columns:
log.info(f"Adding {raw} column")
table.add_column(raw, str)

if geojson and GEOMETRY_COLUMN not in columns:
log.info("Adding geometry column")
table.add_column(GEOMETRY_COLUMN, str)
Expand Down Expand Up @@ -107,6 +114,9 @@ def geocode_table(
update[latitude_column] = result.latitude
update[longitude_column] = result.longitude

if raw:
update[raw] = result.raw

table.update(pk, update, conversions=conversions)
count += 1

Expand Down
26 changes: 24 additions & 2 deletions tests/test_geocode_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def test_capture_raw(db, db_path, geocoder):
],
)

print(result.stdout)
assert 0 == result.exit_code

for row in table.rows:
Expand Down Expand Up @@ -457,7 +456,6 @@ def test_capture_raw_custom(db, db_path, geocoder):
],
)

print(result.stdout)
assert 0 == result.exit_code

for row in table.rows:
Expand All @@ -467,3 +465,27 @@ def test_capture_raw_custom(db, db_path, geocoder):
result = geo_table.get(row["id"])

assert raw == result


def test_geocode_table_raw(db, geocoder):
table = db[TABLE_NAME]
geo_table = db[GEO_TABLE]

RAW = "raw"

assert "latitude" not in table.columns_dict
assert "longitude" not in table.columns_dict
assert "raw" not in table.columns_dict

count = geocode_table(db, TABLE_NAME, geocoder, "{id}", raw=RAW)

# did we get the whole table?
assert count == table.count

for row in table.rows:
assert type(row.get(RAW)) == str

raw = json.loads(row[RAW])
result = geo_table.get(row["id"])

assert raw == result