Skip to content

Add pandas 3 compatibility for string dtype handling#716

Open
guillaume-vignal wants to merge 27 commits into
MAIF:masterfrom
guillaume-vignal:fix_pandas_3_object_str
Open

Add pandas 3 compatibility for string dtype handling#716
guillaume-vignal wants to merge 27 commits into
MAIF:masterfrom
guillaume-vignal:fix_pandas_3_object_str

Conversation

@guillaume-vignal

@guillaume-vignal guillaume-vignal commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.0 in pyproject.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.

Comment thread shapash/utils/transform.py Outdated
Comment thread shapash/utils/clustering.py Outdated
Comment thread shapash/webapp/webapp_launch_DVF.py Outdated
Comment thread tutorial/production_and_ops/tuto-prod03-batch-scoring-parquet.ipynb Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Comment thread shapash/utils/clustering.py Outdated
Comment thread shapash/webapp/webapp_launch_DVF.py Outdated
Comment thread tutorial/production_and_ops/tuto-prod03-batch-scoring-parquet.ipynb

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 40 out of 40 changed files in this pull request and generated 9 comments.

Comment thread tutorial/plots_and_charts/tuto-plot06-prediction_plot.ipynb Outdated
Comment thread tutorial/plots_and_charts/tuto-plot06-prediction_plot.ipynb Outdated
Comment thread tutorial/plots_and_charts/tuto-plot03-features-importance.ipynb Outdated
Comment thread tutorial/plots_and_charts/tuto-plot07-additional_plots_visualizations.ipynb Outdated
Comment thread shapash/utils/transform.py Outdated
Comment thread shapash/plots/plot_correlations.py Outdated
Comment thread shapash/utils/check.py Outdated
Comment thread shapash/utils/check.py Outdated
Comment thread pyproject.toml Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 40 out of 40 changed files in this pull request and generated 6 comments.

Comment thread tutorial/plots_and_charts/tuto-plot06-prediction_plot.ipynb
Comment thread tutorial/plots_and_charts/tuto-plot03-features-importance.ipynb
Comment thread shapash/utils/check.py Outdated
Comment thread shapash/utils/check.py Outdated
Comment thread shapash/plots/plot_correlations.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 regex branch, 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")

Comment thread shapash/utils/category_encoder_backend.py
Comment thread shapash/plots/plot_correlations.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 40 out of 40 changed files in this pull request and generated 3 comments.

Comment thread shapash/backend/lime_backend.py
Comment thread shapash/explainer/consistency.py
Comment thread shapash/webapp/webapp_launch_DVF.py Outdated
@guillaume-vignal guillaume-vignal requested a review from Copilot June 11, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 40 out of 40 changed files in this pull request and generated 3 comments.

Comment thread shapash/utils/transform.py
Comment thread shapash/utils/check.py
Comment thread shapash/utils/check.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 40 out of 40 changed files in this pull request and generated 1 comment.

Comment thread shapash/backend/lime_backend.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.

Comment thread shapash/plots/plot_correlations.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 2 comments.

Comment thread shapash/backend/lime_backend.py Outdated
Comment thread shapash/backend/lime_backend.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 43 out of 43 changed files in this pull request and generated 2 comments.

Comment thread shapash/backend/base_backend.py Outdated
Comment thread shapash/backend/lime_backend.py Outdated
Comment thread shapash/backend/base_backend.py
Comment thread shapash/backend/lime_backend.py
Comment thread shapash/explainer/consistency.py
Comment thread shapash/plots/plot_correlations.py
Comment thread shapash/report/common.py
Comment thread tutorial/common/tuto-common02-colors.ipynb
Comment thread tutorial/domain_examples/tuto-domain02-glm-regression.ipynb
Comment thread tutorial/generate_report/shapash_report_example.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 4 comments.

Comment thread tests/unit_tests/utils/test_category_encoders_backend.py
Comment thread tests/unit_tests/utils/test_transform.py
Comment thread shapash/plots/plot_correlations.py
guillaume-vignal and others added 4 commits June 18, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support pandas 3 string dtype across string-handling utilities

3 participants