Skip to content

[DSEW CPR] Pass through python-black #1577

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

Closed
wants to merge 8 commits into from
Closed

[DSEW CPR] Pass through python-black #1577

wants to merge 8 commits into from

Conversation

dshemetov
Copy link
Contributor

@dshemetov dshemetov commented Apr 13, 2022

Description

Something of a personal preference, as I am usually into black's output. Some main changes:

  • consistent white spaces
  • consistent use of " versus '
  • takes advantage of () to separate long pandas lines, i.e.
# Turn this 
pd.merge(df, max_ts_by_group, on=["publish_date", "geo_id"], how="outer").assign(is_max_group_ts=lambda df: df["timestamp"] == df["max_timestamp"]).drop(["max_timestamp"], axis=1))

# Into this
(
  pd.merge(df, max_ts_by_group, on=["publish_date", "geo_id"], how="outer")
  .assign(is_max_group_ts=lambda df: df["timestamp"] == df["max_timestamp"])
  .drop(["max_timestamp"], axis=1)
)

Merge after the interpolation work.

@krivard krivard changed the base branch from main to ds/dsew-interpolation April 14, 2022 13:42
@dshemetov
Copy link
Contributor Author

@krivard let's merge this into #1555 only when we're ready to merge that one, so we don't clutter the diffs there.

@dshemetov
Copy link
Contributor Author

dshemetov commented Apr 14, 2022

Also let me know if you have any objections to this. It doesn't look great in some parts (like where it has to break many composed functions up and it creates too much white space by creating too many lines with just a single open bracket), but at least it gives us consistency.

Copy link
Contributor

@krivard krivard left a comment

Choose a reason for hiding this comment

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

Okay this is a really detailed pass but I don't want it to be overwhelming so here's a rough guide:

General case:

  • quote normalization is universally 💯
  • space-padding around operators, assignment, and parameter specification is universally 💯
  • using parens to reduce the need for backslashes and permit the method name to be the first item on a line is almost always 💯
  • same-line vs multi-line formatting decisions are too context-dependent to be able to rely on an automated tool 👎

Specifics:

  • I marked particularly good reformats with 💯
  • I marked particularly bad reformats with "this is worse"
  • I marked borderline reformats with "ehhhhhh"
  • Anything unmarked is either covered by one of the universal 💯 s above, or was a moderate improvement, neutral, or escaped notice

I'm not 100% sure what this means -- Black doesn't seem to let you turn off particular formatting rules. There does seem to be a mechanism for identifying blocks of code that Black shouldn't touch, but then it wouldn't do the things we do like, and we'd have to maintain an awful lot of those block markers.

header.find("%") < 0,
]
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

this one however is fine, probably because there are fewer levels involved

@dshemetov
Copy link
Contributor Author

dshemetov commented Apr 15, 2022

Hm yea, well it's good to learn that same line versus multi-line decisions are really a big weakness of this tool.

Maybe we just keep this a one-off run, keep the parts we like, reject parts we don't, and move on? Like, we're clearly not ready to move to a bot-automated usage, but it's useful if it makes good decisions in like 80% of the cases and we can manually fix the other 20%.

Base automatically changed from ds/dsew-interpolation to main April 18, 2022 16:17
Copy link
Contributor

@krivard krivard left a comment

Choose a reason for hiding this comment

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

should we refresh this or trash it?

@dshemetov
Copy link
Contributor Author

dshemetov commented Apr 10, 2023

I could go either way:

  • trash: formatting inconsistency is tolerable, fixing it is low priority, also, it's a bit annoying to have to write #fmt: off around blocks where we don't like the formatting
  • refresh: formatting consistency is nice, it's nice to have it automated, so we can focus developer time on more important things

In my personal projects, I use black and just accept its formatting, because I prefer to just not think about it. But as for using it on our team, maybe we should poll our developers' preferences instead.

@nmdefries
Copy link
Contributor

We can close this, CPR has been deprecated.

@dshemetov dshemetov closed this Sep 5, 2023
@dshemetov dshemetov deleted the ds/cpr-style branch September 5, 2023 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants