-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
CLN: replace %s formatting syntax with .format #16130
Comments
Indeed, the f-string syntax would be nice...however, between [6] and [7], I would prefer that we use [7]. True, it is slightly more verbose, but it is also a little clearer. |
I'd like to contribute on this one. One question: what about other specifiers, like %d? For some strings, using something like [7] can make some strings that were readable a little less so. For example:
|
in that case i would use [6] |
Keep in mind that some classes define their own formatting rules, e.g. In [45]: dts = pd.Timestamp('2017-01-01T12:03:04')
In [46]: '{:%Y-%m-%d %T}'.format(dts)
Out[46]: '2017-01-01 12:03:04' |
If we really wanted to, we can add this flake8 plugin when we're done: https://github.com/gforcada/flake8-pep3101 output:
|
@jschendel I have some changes for this issue. Can we coordinate so I don't make a request for anything you've already done or are working on? |
@cbertinato Sure, just let me know what you're working on/want to work on and I'll steer clear. I saw that you made a commit for I don't really have a backlog of stuff I've started working on but haven't submitted a PR for; been working on this in (somewhat) coherent chunks and submit PRs as I finish the chunks. I just started some work on I don't have a set plan for what I'm going to do and when either. I've mostly been trying to read over the pandas codebase to get a better understanding of it, and figured I'd do something productive along the way! |
Sounds good. The only I'm working is getting changes to |
I'd like to get your opinions on an issue that arose while working through Here is one example where a format string is passed to a function (1939):
which gets passed on to another function (1876):
The issue is that if the user specifies anything other than One way to move all of the internal code to Thoughts on how best to proceed? |
I think you can get around it with from functools import partial
if self.float_format is None and self.fixed_width:
float_format = partial('{value:.{digits:d}f}'.format, digits=self.digits) and def base_formatter(v):
return float_format(value=v) if notna(v) else self.na_rep |
Progress toward issue pandas-dev#16130. Converted old string formatting to new string formatting in io/formats/format.py.
Progress toward issue pandas-dev#16130. Converted old string formatting to new string formatting in core/indexing.py.
Progress toward issue pandas-dev#16130. Converted old string formatting to new string formatting in core/indexing.py.
Progress toward issue pandas-dev#16130. Converted old string formatting to new string formatting in core/indexing.py.
Progress toward issue pandas-dev#16130. Converted old string formatting to new string formatting in io/formats/format.py.
progress towards pandas-dev#16130
progress towards pandas-dev#16130
progress towards pandas-dev#16130
progress towards pandas-dev#16130
progress towards pandas-dev#16130
progress towards pandas-dev#16130
I think we can close this issue. I could not see any outstanding cases when performing a grep search. |
Closing in favor of #29547 |
only showing a small snippet. There are about 1000 separate incidents of this (including .py and .pyx) files.
This is pretty easy to change of course (though its somewhat manual).
It provides a cleaner syntax (include kwargs optionally, which makes it more readable). and guards
against accidently trying to format a list/tuple.
So replacing [5] with [6] or [7]
Ideally we would even use f-strings, but only >= 3.6 :<
The text was updated successfully, but these errors were encountered: