Skip to content

feat: stabilize dtype conversion across pandas, pyarrow, and modin test constructors#3749

Merged
camriddell merged 4 commits into
narwhals-dev:mainfrom
camriddell:stabilize-convert_dtypes
Jul 7, 2026
Merged

feat: stabilize dtype conversion across pandas, pyarrow, and modin test constructors#3749
camriddell merged 4 commits into
narwhals-dev:mainfrom
camriddell:stabilize-convert_dtypes

Conversation

@camriddell

Copy link
Copy Markdown
Member

Happy to discuss this. Not converting dtypes is going to be a good thing to test as part of #3717

pandas.{DataFrame,Series}.convert_dtypes(…) will automatically downcast whole number floats (e.g. 1.0, 2.0, 3.0) to integer datatypes. The only option within that method to avoid this behavior is to provide convert_integer=False, which both: retains the whole number floats columns as a float dtype, but also then ignores any actual integer columns and thus converts them int64.

This PR performs each conversion column-by-column and eagerly check for whole number float to control the convert_integer parameter. I found this to be the least invasive option while still allowing our test suite to continue passing (locally).


stabilize dtype conversion across pandas, pyarrow, and modin test constructors

Introduce a shared helper to detect integer-like floats (e.g. 1.0, 2.0) and use it to control pandas' convert_dtypes(…) to avoid downcasting floats to integers.

Description

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

camriddell and others added 3 commits July 2, 2026 17:13
constructors

Introduce a shared helper to detect integer-like floats (e.g. 1.0, 2.0)
and use it to control pandas' `convert_dtypes(…)` to avoid downcasting
floats to integers.

@FBruzzesi FBruzzesi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for taking the initiative @camriddell - I have no objections on this! I wonder if the constructors in #3552 should follow the same approach. WDYT?

@FBruzzesi FBruzzesi added enhancement New feature or request tests labels Jul 3, 2026
@dangotbanned

Copy link
Copy Markdown
Member

Seems reasonable 🙂

@camriddell have you considered raising an issue in pandas?
I have to imagine it's cheaper for them not to do whatever inference is required for "whole number floats" 😅

@camriddell

Copy link
Copy Markdown
Member Author

Thanks for taking the initiative @camriddell - I have no objections on this! I wonder if the constructors in #3552 should follow the same approach. WDYT?

Yeah, I think those constructors should take the same approach.

@FBruzzesi FBruzzesi changed the title enh: stabilize dtype conversion across pandas, pyarrow, and modin test constructors feat: stabilize dtype conversion across pandas, pyarrow, and modin test constructors Jul 6, 2026
@FBruzzesi

Copy link
Copy Markdown
Member

@camriddell I am not sure what's going on with the release drafter 🫥 I would try to merge and see what happens there

@camriddell camriddell merged commit 83d34d0 into narwhals-dev:main Jul 7, 2026
24 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants