You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH Render categorical splits in tree exporters - #34809
Addresses categorical exporting in #33965. Following review feedback, this PR focuses on standalone decision trees and ExtraTrees in the existing exporters. The public export_dict API is not included.
What does this implement/fix?
Add categorical split rendering to export_text, export_graphviz and plot_tree, preserving numerical output.
Standalone classifiers and regressors show original category labels. Text reports list the categories on each branch; Graphviz and plots show the full left-category set.
Missing/unknown routing is shown explicitly. Shared helpers reuse tree routing logic and handle category lookup, formatting and escaping.
Forest sub-estimators with categorical splits raise a clear error because they lack their own category encoder. Numeric-only and single-leaf forest trees still export normally.
The scope has been reduced by removing the integer-code fallback, max_categories, truncation and smaller-side selection. No new public display parameters are introduced. Large category sets can produce long labels; this limitation is documented.
Five files changed: +122/-11 implementation (including docstrings), +213 tests and +30 documentation; total +365/-11, 108 fewer added lines than the previous version.
Validation
Local tree suite and exporter doctests: 972 passed, 9 skipped. All 52 tree-guide doctest examples passed. Lint and formatting passed before incorporating the latest upstream merge, which did not change the tree files.
Forest regression coverage checks categorical errors, successful numeric-only export and single-leaf export across all three exporters and four forest types.
New CI was triggered by the push of 68ffefb; results are pending. Previous green CI does not validate this simplified version.
Possible follow-ups
Support original category labels when exporting forest sub-estimators, with an agreed way to retain or supply their mapping.
Discuss optional display limits and smaller-side rendering separately if needed for large category sets.
The pull request addresses an existing issue that is ready for contribution (e.g. not tagged as 'Needs Triage', 'Needs Decision', ...). If you are proposing a new feature, please open an issue to discuss it first.
There are no other open pull requests already targeting the same issue.
You have followed the pull request checklist. In particular, linting and tests should pass.
lcrmorin
changed the title
Export dict 20051
Add Export dict #20051
Aug 24, 2026
lcrmorin
changed the title
ENH Export decision trees as dictionaries and render categorical splits
ENH Export decision trees as dictionaries
Nov 5, 2026
This PR exceeds the recommended size of 500 lines changed. Consider splitting it into smaller PRs to ease the review process. Please make sure you read our Contributing guide and in particular our Pull Request guidelines
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
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.
Reference Issues/PRs
Addresses categorical exporting in #33965. Following review feedback, this PR focuses on standalone decision trees and ExtraTrees in the existing exporters. The public
export_dictAPI is not included.What does this implement/fix?
Add categorical split rendering to
export_text,export_graphvizandplot_tree, preserving numerical output.The scope has been reduced by removing the integer-code fallback,
max_categories, truncation and smaller-side selection. No new public display parameters are introduced. Large category sets can produce long labels; this limitation is documented.Five files changed: +122/-11 implementation (including docstrings), +213 tests and +30 documentation; total +365/-11, 108 fewer added lines than the previous version.
Validation
68ffefb; results are pending. Previous green CI does not validate this simplified version.Possible follow-ups
export_dictAPI for sklearn.tree.export_dict #20051. Its implementation is preserved on a separate branch, which will need adapting to the simplified helpers.AI tools assisted with these changes.