-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PEP: pandas/core round 2 #11951
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
PEP: pandas/core round 2 #11951
Conversation
@@ -179,7 +192,8 @@ class Categorical(PandasObject): | |||
[a, b, c, a, b, c] | |||
Categories (3, object): [a < b < c] | |||
|
|||
>>> a = Categorical(['a','b','c','a','b','c'], ['c', 'b', 'a'], ordered=True) | |||
>>> a = Categorical(['a','b','c','a','b','c'], ['c', 'b', 'a'], \ | |||
ordered=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be indented
Per PEP8, we should prefer using parenthesis to explicit continuations with |
@jorisvandenbossche yes more than happy for others to deal with the formatting nit-picking :) I agree a single tool is prob the best (for both usage) and validation via Travis. (and fix the docs to do the same). |
f816fae
to
6a77470
Compare
Please could you include the command you used in the commit messages/PR post? :) |
@@ -179,13 +191,13 @@ class Categorical(PandasObject): | |||
[a, b, c, a, b, c] | |||
Categories (3, object): [a < b < c] | |||
|
|||
>>> a = Categorical(['a','b','c','a','b','c'], ['c', 'b', 'a'], ordered=True) | |||
>>> a = Categorical(['a','b','c','a','b','c'], ['c', 'b', 'a'], \ | |||
ordered=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples shouldn't use \
for continuation. This line should just be formatted as you would do with normal python code, so something like
>>> a = Categorical(['a','b','c','a','b','c'], ['c', 'b', 'a'],
ordered=True)
There are also some cases of this in other examples I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unsure of those...good to know.
46f8158
to
ab8ae80
Compare
I'm not completely sure I like this. It looks nice, but maybe a bit too expansive. I know the PyDev debugger would force you to go over every single line before stepping into DataFrameFormatter which would get annoying after awhile. |
@rockg personally I find 1 kw arg per line MUCH more clear. Yes debugging is a tiny bit trickier, but its all laid out better. |
@jreback I agree that it looks nicer just thinking of some practical considerations (one could think of some rule that if it's >5 lines of arguments do something different, but that won't look as nice and will be difficult to automatically format). |
@rockg yeh, certainly someone could play with the |
this is currently disabled in the as an aside can you put the notes you have above in |
warn("Creating a 'Categorical' with 'levels' is deprecated, use 'categories' instead", | ||
FutureWarning, stacklevel=2) | ||
if levels is not None: | ||
warn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no line break here
I brought this up above. That is an output of yapf. I think the algorithm design is essentially to move all the arguments to one line and then apply the rules to that (so even though the line is not 80 characters now, moving up the second line of arguments would make it so, causing it to be split as you see it). I think the only option would be: SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT However, I think that would not wrap lines with really long arguments and split lines with shorter argument lists or not wrap at all. Is there any case where we want to wrap (e.g., many arguments)? |
@wesm Does "as long as it fits within 80 characters" mean the entire signature or separate lines of the signature. Should the example given by @jorisvandenbossche be modified or left as is? |
Would be good to see what knobs you used, so we can play along at home/tweak them. |
@rockg each line of code (signature can be multiple lines) |
This version you see used no knobs, but in spirit a knob of SPLIT_PENALTY_AFTER_OPENING_BRACKET=1000000 was used (it was applied manually rather than lose all the other work) after it was decided to change it. I think the only other one that may be needed is SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT to be larger in order to not split function signatures. |
@jreback What are your opinions on this? You were in favor of the multiple lines. |
@hayd you are somewhat more familiar with yapf? |
Seems like this does it for this case:
|
I'll try these two knobs on the files so we can see how it looks. |
@rockg ah yes indeed! Didn't try that one (hadn't guessed it from the name) |
@jorisvandenbossche Please take a look. I ran with:
|
That's looking great! I think this addresses most/all of @wesm's concerns ? The couple of awkward looking lines I think will look awkward no matter what (without a refactor)... We should add a [yapf] section to setup.cfg with those options. |
Cool that's looking good. |
Indeed, looks good! @rockg the result we see now, is this fully the output of the yapf config you gave above, or is this still some manual clean-up as well? |
There is still manual work including docstrings/error strings beyond 79 chars and then fixing any formatting yapf couldn't fix (this was quite small). I played with docformatter but that did not work very well as it ended up eliminating all the numpydoc formatting. Also, keeping split_penalty_after_opening_bracket to unbreakable would be preferred but then the imports became indented to match the opening bracket. I could not get the both of these to work together, but maybe that level of indentation in imports is fine and the open parentheses formatting is more important. |
For example, in the settings above or split_penalty_after_opening_bracket set to unbreakable, instances like this still need fixing (both not splitting on the parenthesis and then splitting the error line). These were all fixed manually. We can try and open an issue with yapf and see if they can fix this.
|
@rockg ok, can you update and rebase. |
4e0e52a
to
00df805
Compare
all ok with this? ideally want to merge this and then have @rockg finish up the rest, so we can actually turn on the checking in travis (for |
@rockg can you rebase again, ping when green. any final comments? |
3c45f56
to
5419f10
Compare
@jreback All set. |
@rockg thank you sir! of course followups welcome
|
FYI I'm mucking around in |
Fix layout and pep8 compliance for categorical, common, and frame. Used YAPF with default settings and then manual modifications including:
-fixing line length of comments/docstrings for pep8 compliance
-converting lambdas to functions for pep8 compliance
-change YAPF default formatting of error strings
-change some YAPF line break choices to make them more natural in my eyes. For example converting
to