Skip to content

BUG: Preserve dtype for NA columns during DataFrame reindex#65159

Draft
jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
jbrockmendel:bug-axis1-arith
Draft

BUG: Preserve dtype for NA columns during DataFrame reindex#65159
jbrockmendel wants to merge 2 commits intopandas-dev:mainfrom
jbrockmendel:bug-axis1-arith

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • Fixes BlockManager._make_na_block to use the interleaved dtype of existing blocks when creating NA columns during reindex, instead of always defaulting to float64
  • For extension dtypes (ArrowDtype, nullable Int64, etc.), creates the array directly with the dtype's own NA value
  • For datetime64/timedelta64, uses NaT instead of NaN
  • Fixes _slice_take_blocks_ax0 placement split logic to use the same dtype inference, so 1D-only EA blocks are correctly split per-column
  • Fixes DataFrame.combine to catch TypeError alongside ValueError when casting all-NA columns

closes #59529
closes #63288

Test plan

  • Added test_frame_sub_series_datetime_axis1 — GH#59529 reproducer
  • Added test_frame_with_frame_reindex_pyarrow_columns — GH#63288 reproducer
  • Added test_frame_with_frame_reindex_nullable_int_columns — nullable Int64 variant
  • Added test_frame_with_frame_reindex_timedelta_columns — timedelta variant
  • Updated test_frame_with_frame_reindex expected output (NaT instead of NaN for non-overlapping datetime columns)
  • All existing tests pass (frame arithmetic, internals, reindex, arrow, masked, combine_first, series arithmetic)

🤖 Generated with Claude Code

…, GH#63288)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…lock

Use na_value_for_dtype to produce unit-aware NaT values and short-circuit
the datetime/timedelta path to preserve exact resolution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant