Skip to content

Improve _EstimatorPrettyPrinter to use an indentation style a bit more consistent with black #21240

@ogrisel

Description

@ogrisel

The current indentation style used in _EstimatorPrettyPrinter is too horizontal and suboptimal rendering of complex pipelines and column transformers in the notebook HTML widgets. See for instance:

https://scikit-learn.org/stable/auto_examples/compose/plot_column_transformer_mixed_types.html#html-representation-of-pipeline

image

I think using a more vertical indentation style would help (and would furthermore be more consistent with the black formatting we use in our code base):

For this specific example black might over-do it a bit (see below) although I still find it better than what we currently have.

Pipeline(
    steps=[
        (
            "preprocessor",
            ColumnTransformer(
                transformers=[
                    (
                        "num",
                        Pipeline(
                            steps=[
                                ("imputer", SimpleImputer(strategy="median")),
                                ("scaler", StandardScaler()),
                            ]
                        ),
                        ["age", "fare"],
                    ),
                    (
                        "cat",
                        OneHotEncoder(handle_unknown="ignore"),
                        ["embarked", "sex", "pclass"],
                    ),
                ]
            ),
        ),
        ("classifier", LogisticRegression()),
    ]
)

Or maybe we could find a middle ground?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Discussion

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions