Geospatial Postprocessing#
Geographic postprocessing in Superset transforms coordinate data in pandas DataFrames as part of the query postprocessing pipeline. All three functions live in superset/utils/pandas_postprocessing/geography.py and are exported via superset/utils/pandas_postprocessing/__init__.py so callers can import them from superset.utils.pandas_postprocessing.
Functions#
| Function | Input column(s) | Output column(s) |
|---|---|---|
geohash_decode | geohash string | longitude, latitude |
geohash_encode | longitude, latitude | geohash string |
geodetic_parse | geodetic point string (geopy Point) | longitude, latitude, (optional) altitude |
Each function appends or overwrites columns using _append_columns from utils.py, which calls DataFrame.assign (overwrite) or pd.concat (append) depending on whether source and target column names are identical.
Error Handling#
All three functions catch ValueError from the underlying library calls and re-raise as InvalidPostProcessingError with these messages:
geohash_decode→"Invalid geohash string"geohash_encode→"Invalid longitude/latitude"geodetic_parse→"Invalid geodetic string"
Known Issue: Empty DataFrame Raises Misleading Error#
geohash_decode and geodetic_parse both fail with a misleading error when the input DataFrame has zero rows.
The root cause is the zip(*...) unpack pattern used by both functions :
lonlat_df["latitude"], lonlat_df["longitude"] = zip(
*df[geohash].apply(geohash_lib.decode), strict=False
)
On an empty DataFrame, apply returns an empty Series, zip(*empty_series) produces nothing, and the tuple assignment raises ValueError: not enough values to unpack. The except ValueError block then surfaces this as InvalidPostProcessingError("Invalid geohash string") — even though no geohash string was malformed.
The same structural bug exists in geodetic_parse , which would raise "Invalid geodetic string" under the same condition.
Effect: Any chart using geohash-decode or geodetic-parse postprocessing will show a data-format error message when the underlying query returns zero rows, rather than rendering a "no data" state. This causes debugging effort to be misdirected toward data quality rather than query filters.
Suggested fix: Guard with an early return of the input DataFrame before the zip unpack when df is empty. This reserves the ValueError/InvalidPostProcessingError path for genuine decode failures. No merged fix exists as of this writing.
Testing#
Unit tests live in tests/unit_tests/pandas_postprocessing/test_geography.py. They cover the happy path for all three functions using the lonlat_df fixture but do not cover empty DataFrame inputs or error paths — the known empty-DataFrame bug is untested.
Related Files#
| File | Purpose |
|---|---|
superset/utils/pandas_postprocessing/geography.py | All three geo functions |
superset/utils/pandas_postprocessing/utils.py | _append_columns, validate_column_args |
superset/utils/pandas_postprocessing/__init__.py | Package exports |
tests/unit_tests/pandas_postprocessing/test_geography.py | Unit tests |