Skip to content

fix: type a column the same however a result was paged or split - #480

Merged
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/concat-keeps-types
Dec 2, 2026
Merged

thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:fix/concat-keeps-types

Conversation

@thodson-usgs

@thodson-usgs thodson-usgs commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

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 as method_category came back as str or object depending on how the rows fell into pages.

combining._concat_frames runs pd.concat(frames, ignore_index=True).infer_objects(), and replaces pd.concat where pages (transport.pagination.paginate) and chunks (combining._combine_chunk_frames) are combined. Each object column then gets its type from its values, whatever the split. The fix covers the waterdata, ngwmn, and nwdc getters.

Measured with pandas 3.1.2 (2026-12-02):

Frames combined Before After
str + all-null object str
float64 + all-null object object float64
datetime64[us, UTC] + all-null object datetime64[us, UTC]
bool or list + all-null object object
  • infer_objects re-types every object column, not only the ones a null page widened.
  • A GeoDataFrame keeps its type, CRS, and geometry dtype.
  • A first version of this PR dropped the all-null columns before the concat, which is pandas' own workaround. It produced the same types in 55 more lines, and was not faster on pandas 3.

Overlap with #479. #479 repairs the same symptom twice: ogc.shaping._infer_object_cols (afdc0b7, with a NEWS entry) and bulk._retrieval._typed_like. After this PR merges, #479 should drop both and call _concat_frames in _merge.

Evidence

  • Before (main, 67ff6f1): test_combine_chunk_frames_types_a_column_the_same_however_it_was_split and test_walk_pages_types_a_column_the_same_however_it_was_paged fail.
    After (492c91c): they pass, along with a new bool-with-None case.
  • On 492c91c: 1,681 tests pass offline, and coverage is 99.05%. ruff, ruff format, mypy (strict), lint-imports, xenon, and complexipy pass.
  • Cost, for 200 pages of 10,000 rows and 30 columns on pandas 3.1.2: 18 ms when the pages agree on every type, and 73 ms with an all-null text page every 50 pages. The previous implementation took 42 ms and 78 ms.

Merge Danger

Door: two-way.

Blast Radius: column types of paged and chunked results.

A column that was object because one page or chunk held only nulls now has the type of its values: str on pandas 3 for text, and float64 or datetime64 on either pandas. Code that tested for object on such a column now sees the more specific type. Re-date the NEWS entry to the merge date.

🤖 Generated with Claude Code

@thodson-usgs thodson-usgs added v1 Non-breaking: can merge for the next 1.x release bug Something isn't working labels Dec 2, 2026
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
thodson-usgs force-pushed the fix/concat-keeps-types branch from 8f3f2ad to 492c91c Compare December 2, 2026 22:35
@thodson-usgs
thodson-usgs marked this pull request as ready for review December 2, 2026 22:42
@thodson-usgs
thodson-usgs merged commit 664b734 into DOI-USGS:main Dec 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working v1 Non-breaking: can merge for the next 1.x release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant