Add pandas 3 compatibility for string dtype handling#716
Open
guillaume-vignal wants to merge 27 commits into
Open
Add pandas 3 compatibility for string dtype handling#716guillaume-vignal wants to merge 27 commits into
guillaume-vignal wants to merge 27 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make Shapash compatible with pandas 3’s default string dtype inference by updating string/categorical dtype checks across core utilities, examples, and tests, and by bumping the minimum supported pandas version.
Changes:
- Update string/categorical column detection logic in utilities and example code to account for pandas 3 string inference.
- Adjust unit tests’ expected preprocessing metadata (
data_type) to reflect string dtype handling changes. - Bump pandas minimum version to
>=2.3.0inpyproject.toml.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tutorial/production_and_ops/tuto-prod03-batch-scoring-parquet.ipynb | Updates dtype-based selection before Parquet write to cast text-like columns. |
| tests/unit_tests/utils/test_transform.py | Updates expected data_type values in preprocessing-mapping related tests. |
| tests/unit_tests/utils/test_columntransformer_backend.py | Updates expected data_type values in CT inverse/transform tests. |
| tests/unit_tests/utils/test_check.py | Updates expected data_type values in preprocessing consistency tests. |
| tests/unit_tests/utils/test_category_encoders_backend.py | Updates expected data_type values in category-encoder backend tests. |
| tests/unit_tests/explainer/test_smart_predictor.py | Updates expected data_type values used in preprocessing checks. |
| tests/unit_tests/decomposition/test_inverse_contribution.py | Updates expected data_type values used in inverse contribution tests. |
| shapash/webapp/webapp_launch_DVF.py | Updates example categorical feature detection for encoding. |
| shapash/utils/transform.py | Updates categorical missing-value handling selection logic. |
| shapash/utils/clustering.py | Updates categorical detection for color encoding in clustering/plots. |
| pyproject.toml | Raises minimum pandas version to >=2.3.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
shapash/utils/check.py:421
- In the
regexbranch, the DataFrame-type error message incorrectly mentions the upper/lower method, which can mislead users when diagnosing invalid postprocessing configuration.
if not pd.api.types.is_string_dtype(x[key]):
raise ValueError(f"Expected string object to modify with upper/lower method in {key} dict")
milton-minervino
requested changes
Jun 15, 2026
Co-authored-by: milton-minervino <milton.minervino@inria.fr>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…e-vignal/shapash into fix_pandas_3_object_str
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #714
This PR updates several string-related checks to align with pandas 3, where text columns are inferred as str instead of object by default.
Some parts of the codebase still assume text data uses the object dtype. Under pandas 3, this can lead to missed categorical columns, incorrect type classification, or rejected string postprocessing.
This change targets pandas 3 behavior. Pandas 2 compatibility is still supported