fix(ogc): keep the frame type when a result is empty - #373
Merged
thodson-usgs merged 1 commit intoAug 14, 2026
Conversation
thodson-usgs
force-pushed
the
fix/empty-result-frame-type
branch
from
August 13, 2026 01:36
ca1cf51 to
efffe5f
Compare
thodson-usgs
force-pushed
the
fix/empty-result-frame-type
branch
from
August 13, 2026 01:52
efffe5f to
d18b0c2
Compare
This was referenced Aug 13, 2026
thodson-usgs
force-pushed
the
fix/empty-result-frame-type
branch
from
August 14, 2026 16:00
d6ea9e1 to
335dedb
Compare
thodson-usgs
marked this pull request as ready for review
August 14, 2026 19:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Every OGC getter returns a
GeoDataFramewhen its filter matches at least one row, and a plainDataFramewhen it matches none.So
.geometry,.to_crs(),.plot(), andpd.concatacross a loop of per-site calls break only on the empty result — the case least likely to be covered by a caller's tests. It is also invisible fromdf.columns, because thegeometrycolumn is still listed.Why
ogc/shaping.py::_empty_feature_frameexists precisely to prevent this; its docstring calls itself "the single home for this empty-page contract", because a laterpd.concat([empty_page, geo_page])would otherwise downgrade the result and strip geometry/CRS.But
_deal_with_emptyruns last, on every getter, 160 lines away in the same file — and built a freshpd.DataFrame(columns=properties), discarding the guarantee it had just been handed.The fix
Reindex the frame we were given instead of constructing a new one. That applies the schema's columns while keeping the concrete class — and the
geometrydtype with it:The plain-pandas path is unchanged:
pd.DataFrame().reindex(columns=[...])is still apd.DataFrame.Testing
DataFramesubclass rather than real geopandas, so the invariant is checked even where geopandas is absent (it is not in the[test]extra, only[nldi]and[doc]). Verified to fail against the old line and pass against the new one.mypy --strict,ruff,xenon,complexipy,lint-importsall pass.Found by the scan in #372, split out because it changes user-visible behavior. Independent of #372 — branches off main.
🤖 Generated with Claude Code
https://claude.ai/code/session_01BTaSm7HmVb94RSJiKW4WAS