Skip to content

Commit f5550e2

Browse files
committed
CLN: fix all flake8 warnings in pandas/io
I suppressed warnings in test_parsers.py because of the amount of literal strings in the file. Author: Wes McKinney <wes@cloudera.com> Closes #12096 from wesm/style/io and squashes the following commits: d7dbaeb [Wes McKinney] Address comments on parse_dates part of docstring 01b6930 [Wes McKinney] CLN: fix all flake8 warnings in pandas/io
1 parent 95f5ba4 commit f5550e2

38 files changed

+3262
-2448
lines changed

pandas/io/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Data IO api
33
"""
44

5+
# flake8: noqa
6+
57
from pandas.io.parsers import read_csv, read_table, read_fwf
68
from pandas.io.clipboard import read_clipboard
79
from pandas.io.excel import ExcelFile, ExcelWriter, read_excel

pandas/io/clipboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def read_clipboard(**kwargs): # pragma: no cover
4242
# 1 3 4
4343

4444
counts = set([x.lstrip().count('\t') for x in lines])
45-
if len(lines)>1 and len(counts) == 1 and counts.pop() != 0:
45+
if len(lines) > 1 and len(counts) == 1 and counts.pop() != 0:
4646
kwargs['sep'] = '\t'
4747

4848
if kwargs.get('sep') is None and kwargs.get('delim_whitespace') is None:

pandas/io/common.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@
3030
from urllib.request import urlopen, pathname2url
3131
_urlopen = urlopen
3232
from urllib.parse import urlparse as parse_url
33-
import urllib.parse as compat_parse
3433
from urllib.parse import (uses_relative, uses_netloc, uses_params,
3534
urlencode, urljoin)
3635
from urllib.error import URLError
37-
from http.client import HTTPException
36+
from http.client import HTTPException # noqa
3837
else:
3938
from urllib2 import urlopen as _urlopen
40-
from urllib import urlencode, pathname2url
39+
from urllib import urlencode, pathname2url # noqa
4140
from urlparse import urlparse as parse_url
4241
from urlparse import uses_relative, uses_netloc, uses_params, urljoin
43-
from urllib2 import URLError
44-
from httplib import HTTPException
45-
from contextlib import contextmanager, closing
46-
from functools import wraps
42+
from urllib2 import URLError # noqa
43+
from httplib import HTTPException # noqa
44+
from contextlib import contextmanager, closing # noqa
45+
from functools import wraps # noqa
4746

4847
# @wraps(_urlopen)
4948
@contextmanager
@@ -66,6 +65,7 @@ class DtypeWarning(Warning):
6665

6766
try:
6867
from boto.s3 import key
68+
6969
class BotoFileLikeReader(key.Key):
7070
"""boto Key modified to be more file-like
7171
@@ -78,10 +78,12 @@ class BotoFileLikeReader(key.Key):
7878
Also adds a `readline` function which will split the returned
7979
values by the `\n` character.
8080
"""
81+
8182
def __init__(self, *args, **kwargs):
8283
encoding = kwargs.pop("encoding", None) # Python 2 compat
8384
super(BotoFileLikeReader, self).__init__(*args, **kwargs)
84-
self.finished_read = False # Add a flag to mark the end of the read.
85+
# Add a flag to mark the end of the read.
86+
self.finished_read = False
8587
self.buffer = ""
8688
self.lines = []
8789
if encoding is None and compat.PY3:
@@ -121,7 +123,8 @@ def readline(self):
121123
raise StopIteration
122124

123125
if self.encoding:
124-
self.buffer = "{}{}".format(self.buffer, self.read(8192).decode(self.encoding))
126+
self.buffer = "{}{}".format(
127+
self.buffer, self.read(8192).decode(self.encoding))
125128
else:
126129
self.buffer = "{}{}".format(self.buffer, self.read(8192))
127130

@@ -211,13 +214,15 @@ def _expand_user(filepath_or_buffer):
211214
return os.path.expanduser(filepath_or_buffer)
212215
return filepath_or_buffer
213216

217+
214218
def _validate_header_arg(header):
215219
if isinstance(header, bool):
216220
raise TypeError("Passing a bool to header is invalid. "
217221
"Use header=None for no header or "
218222
"header=int or list-like of ints to specify "
219223
"the row(s) making up the column names")
220224

225+
221226
def _stringify_path(filepath_or_buffer):
222227
"""Return the argument coerced to a string if it was a pathlib.Path
223228
or a py.path.local
@@ -263,8 +268,9 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None,
263268
else:
264269
compression = None
265270
# cat on the compression to the tuple returned by the function
266-
to_return = list(maybe_read_encoded_stream(req, encoding, compression)) + \
267-
[compression]
271+
to_return = (list(maybe_read_encoded_stream(req, encoding,
272+
compression)) +
273+
[compression])
268274
return tuple(to_return)
269275

270276
if _is_s3_url(filepath_or_buffer):
@@ -467,4 +473,4 @@ def _check_as_is(x):
467473
# write to the target stream
468474
self.stream.write(data)
469475
# empty queue
470-
self.queue.truncate(0)
476+
self.queue.truncate(0)

pandas/io/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
55
"""
6+
# flake8: noqa
7+
68
import warnings
79
import tempfile
810
import datetime as dt

0 commit comments

Comments
 (0)