Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical method chaining #4244

Open
rat-nick opened this issue Feb 19, 2024 · 0 comments
Open

Vertical method chaining #4244

rat-nick opened this issue Feb 19, 2024 · 0 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@rat-nick
Copy link

rat-nick commented Feb 19, 2024

When chaining multiple methods together as such:

def f():
    data = item_preprocessor \
        .handle_missing_values(strategy="mean") \
        .multilabel_binarize(["tags"]) \
        .normalize(["price"], methods=["z-score"]) \
        .onehot_encode(categorical_columns=["category"]) \
        .select_features(regex="^ftr.*", columns=["price"])

Black formats as such:

def f():
    data = (
        item_preprocessor.handle_missing_values(strategy="mean")
        .multilabel_binarize(["tags"])
        .normalize(["price"], methods=["z-score"])
        .onehot_encode(categorical_columns=["category"])
        .select_features(regex="^ftr.*", columns=["price"])
    )

It seems more readable as the first method being chained has its own line

def f():
    data = (
        item_preprocessor
        .handle_missing_values(strategy="mean")
        .multilabel_binarize(["tags"])
        .normalize(["price"], methods=["z-score"])
        .onehot_encode(categorical_columns=["category"])
        .select_features(regex="^ftr.*", columns=["price"])
    )
@rat-nick rat-nick added the T: style What do we want Blackened code to look like? label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

1 participant