Repository navigation
fix: type a column the same however a result was paged or split - #480
Merged
Merged
Conversation
A column's type in a combined result depended on how the rows were split. A page or chunk with only nulls in a column has that column as `object`. pandas 3 no longer ignores such a frame when typing a concatenated column (pandas 2.1 deprecated the old behavior, GH 40893), so the combined column widened to `object`. A text column such as `method_category` could then be `object` instead of `str`. Add `combining._concat_frames`, which concatenates the frames and then calls `DataFrame.infer_objects()`, so each `object` column is re-typed from its values. `paginate` and `_combine_chunk_frames` use it in place of `pd.concat`. That covers the `waterdata`, `ngwmn` and `nwdc` getters. `infer_objects()` re-types every `object` column, not only widened ones. A `bool` column beside an all-`None` frame stays `object`. Beside an all-NaN float frame it is `float64` or `object` depending on frame order (measured on pandas 3.1.2). A GeoDataFrame keeps its type, CRS and geometry dtype. Tests cover typing from values for each split, the bool-with-None case, and the chunk-combine path. NEWS.md records the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thodson-usgs
force-pushed
the
fix/concat-keeps-types
branch
from
December 2, 2026 22:35
8f3f2ad to
492c91c
Compare
thodson-usgs
marked this pull request as ready for review
December 2, 2026 22:42
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.
Summary
When one page or chunk has only nulls in a column, that frame types the column
object. pandas 3 no longer ignores such a frame when it types the concatenated column. pandas 2.1 deprecated the old behavior (GH 40893). So a text column such asmethod_categorycame back asstrorobjectdepending on how the rows fell into pages.combining._concat_framesrunspd.concat(frames, ignore_index=True).infer_objects(), and replacespd.concatwhere pages (transport.pagination.paginate) and chunks (combining._combine_chunk_frames) are combined. Eachobjectcolumn then gets its type from its values, whatever the split. The fix covers thewaterdata,ngwmn, andnwdcgetters.Measured with pandas 3.1.2 (2026-12-02):
str+ all-nullobjectstrfloat64+ all-nullobjectobjectfloat64datetime64[us, UTC]+ all-nullobjectdatetime64[us, UTC]boolor list + all-nullobjectobjectinfer_objectsre-types everyobjectcolumn, not only the ones a null page widened.Overlap with #479. #479 repairs the same symptom twice:
ogc.shaping._infer_object_cols(afdc0b7, with a NEWS entry) andbulk._retrieval._typed_like. After this PR merges, #479 should drop both and call_concat_framesin_merge.Evidence
test_combine_chunk_frames_types_a_column_the_same_however_it_was_splitandtest_walk_pages_types_a_column_the_same_however_it_was_pagedfail.After (492c91c): they pass, along with a new bool-with-None case.
Merge Danger
Door: two-way.
Blast Radius: column types of paged and chunked results.
A column that was
objectbecause one page or chunk held only nulls now has the type of its values:stron pandas 3 for text, andfloat64ordatetime64on either pandas. Code that tested forobjecton such a column now sees the more specific type. Re-date the NEWS entry to the merge date.🤖 Generated with Claude Code