Skip to content

fix: pandas 3.0 compatibility for strict string dtype enforcement#209

Merged
tompollard merged 1 commit intotompollard:mainfrom
lukepayyapilli:fix/pandas-3.0-string-dtype-compatibility
Feb 9, 2026
Merged

fix: pandas 3.0 compatibility for strict string dtype enforcement#209
tompollard merged 1 commit intotompollard:mainfrom
lukepayyapilli:fix/pandas-3.0-string-dtype-compatibility

Conversation

@lukepayyapilli
Copy link
Contributor

@lukepayyapilli lukepayyapilli commented Feb 2, 2026

Summary

@tompollard Fixes #207 - Incompatibility with Pandas 3.0+ string dtype.

Pandas 3.0 enforces strict string dtype, which raises TypeError when assigning non-string values to string-typed columns.

Approach

Per the pandas 3.0 migration guide, the recommended approach for library maintainers is:

  1. Detection: Use pd.api.types.is_string_dtype() to detect string columns (works for both object and string dtypes).
  2. Mixed-type assignments: Convert to object dtype with .astype(object) when flexible typing is needed.
  3. Null handling: Use fillna() instead of replace('nan', ...) since pandas 3.0 NA values are actual NA objects, not the string 'nan'.

Changes

tableone/tableone.py

  • In _insert_n_row(): Convert string dtype columns to object dtype before assigning integer counts.

tableone/preprocessors.py

  • In handle_categorical_nulls(): Use fillna() instead of replace('nan', ...) for pandas 3.0 compatibility.

tests/unit/test_tableone.py

  • Fix data_mixed fixture: Convert column to object dtype before assigning string to numeric column.
  • Add two new tests for pandas 3.0 string dtype compatibility.

Testing

  • All 46 tests pass with pandas 3.0.0.

Related

Issue #208 discusses adding version ceilings to dependencies to protect against future breaking changes.

@tompollard
Copy link
Owner

thanks luke!

@tompollard tompollard merged commit 178f81d into tompollard:main Feb 9, 2026
3 checks passed
@lukepayyapilli lukepayyapilli deleted the fix/pandas-3.0-string-dtype-compatibility branch February 10, 2026 00:55
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.

Incompatibility with Pandas 3.0+ string dtype: TypeError when inserting integer into 'str' column

2 participants