Skip to content

Conversation

@SoulSniper1212
Copy link

@SoulSniper1212 SoulSniper1212 commented Nov 11, 2025

Overview

This PR fixes an issue where using scalar row + slice columns indexing (e.g. df[scalar_row, slice_columns]) would not preserve column dtypes properly. The fix implements a special case for this indexing pattern to first extract the column slice, preserving dtypes, then extract the specific row.

Checklist

  • Code changes implemented
  • Tests added to verify the fix
  • Documentation updated (if applicable)

Proof

The fix addresses issue #63071 by handling the scalar row + slice columns case specifically in _LocationIndexer._getitem_lowerdim. The solution first gets the column slice to create a sub-DataFrame with preserved column dtypes, then extracts the required row from this sub-DataFrame. This ensures that the resulting Series maintains the original column dtypes as expected.

Closes #63071

Signed-off-by: SoulSniper1212 <warush23@gmail.com>
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Please always add tests.

Comment on lines +1090 to +1092
# For scalar row + slice columns, process by first getting the column slice
# to preserve dtypes, then extracting the row
# Otherwise, reverse tuple so that we are indexing along columns before rows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't these both say the same thing? To do columns first and then rows?

@mroeschke
Copy link
Member

Based on the contributor's history, I believe this is an AI generated PR so closing.

@mroeschke mroeschke closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.loc[] returns object type instead of float

3 participants