-
-
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 syntax with .format in pandas.io #24454
Conversation
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.
can you use named parameters rather than positional, esp where there are more string to replace
pandas/io/parsers.py
Outdated
@@ -2236,10 +2239,11 @@ def __init__(self, f, **kwds): | |||
raise ValueError('Only length-1 decimal markers supported') | |||
|
|||
if self.thousands is None: | |||
self.nonnum = re.compile('[^-^0-9^%s]+' % self.decimal) | |||
self.nonnum = re.compile( | |||
'[^-^0-9^{decimal}]+'.format(decimal=self.decimal)) |
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.
can you make both of the raw string (r'....'
)
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.
can you add this
pandas/io/pytables.py
Outdated
"value->%s,format->%s,append->%s,kwargs->%s]" | ||
% (t, group, type(value), format, append, kwargs) | ||
) | ||
"cannot properly create the storer for: [{}] [group->{}," |
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.
can you use named parameters here
pandas/io/pytables.py
Outdated
@@ -1590,7 +1594,7 @@ def __unicode__(self): | |||
self.axis, | |||
self.pos, | |||
self.kind))) | |||
return "name->%s,cname->%s,axis->%s,pos->%s,kind->%s" % temp | |||
return "name->{},cname->{},axis->{},pos->{},kind->{}".format(*temp) |
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.
here as well, maybe better to write as
','.join(("[{}->{}".format(key, value) for key, value in zip(['name', 'cname', 'axis', 'pos', 'kind'], temp)
Codecov Report
@@ Coverage Diff @@
## master #24454 +/- ##
===========================================
- Coverage 92.31% 43% -49.31%
===========================================
Files 163 163
Lines 51987 51987
===========================================
- Hits 47990 22356 -25634
- Misses 3997 29631 +25634
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24454 +/- ##
==========================================
+ Coverage 92.38% 92.38% +<.01%
==========================================
Files 166 166
Lines 52321 52321
==========================================
+ Hits 48337 48338 +1
+ Misses 3984 3983 -1
Continue to review full report at Codecov.
|
pandas/io/pytables.py
Outdated
"Consider using min_itemsize to preset the sizes on " | ||
"these columns" % (itemsize, self.cname, c.itemsize)) | ||
"these columns".format( |
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.
many locations still that need to use kwargs
@@ -1840,7 +1849,7 @@ def create_for_block( | |||
""" return a new datacol with the block i """ | |||
|
|||
if cname is None: | |||
cname = name or 'values_block_%d' % i | |||
cname = name or 'values_block_{idx}'.format(idx=i) |
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.
for a single replacement ok with NOT using kwargs
pandas/io/pytables.py
Outdated
@@ -1876,7 +1885,8 @@ def __unicode__(self): | |||
self.dtype, | |||
self.kind, | |||
self.shape))) | |||
return "name->%s,cname->%s,dtype->%s,kind->%s,shape->%s" % temp | |||
return ("name->{},cname->{},dtype->{},kind->{}," |
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.
use the same template as above
let's be consistent about this. a single formatted string need not be named, multiple need to be named. |
pandas/io/parsers.py
Outdated
else: | ||
col = '%s.%d' % (col, cur_count) | ||
col = '{col}.{cnt}'.format(col=col, cnt=cur_count) |
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.
Would be nice to use variable names consistently across modules, so count
instead of int
and column
instead of col
, etc...
@@ -1571,8 +1572,8 @@ def _get_name(icol): | |||
return icol | |||
|
|||
if col_names is None: | |||
raise ValueError(('Must supply column order to use %s as ' | |||
'index') % str(icol)) | |||
raise ValueError(('Must supply column order to use {icol!s} ' |
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.
Do we need to be explicit about type in this and subsequent example?
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.
if you said about '!s', yes. !s is replacing the str function not '%s'.
pandas/io/parsers.py
Outdated
raise ValueError("Unable to convert column %s to " | ||
"type %s" % (column, cast_type)) | ||
raise ValueError( | ||
"Unable to convert column {column} to type {type}".format( |
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.
Does using type
here present any potential conflict with the built-in? Maybe renamed to type_
to err on the side of caution?
FWIW in case we someday want to lint for this, searching for |
@makeajourney can you merge master and update comments? |
2f3648b
to
c509318
Compare
Hello @makeajourney! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 11, 2019 at 02:13 Hours UTC |
CI failed only with python2.7. I have no idea about this problem. |
@jreback Can I divide this pull-request into smaller units? It's too hard to find the problem because too many files changed. |
progress towards pandas-dev#16130
This reverts commit 494ee10.
1f305c8
to
f249d93
Compare
yes that would be best |
progress towards #16130
git diff upstream/master -u -- "*.py" | flake8 --diff