Skip to content

Commit 673bde0

Browse files
committed
Rename source to path_or_buf and flake8
1 parent 28f19f1 commit 673bde0

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

pandas/io/common.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,23 @@ def file_path_to_url(path):
273273
return urljoin('file:', pathname2url(path))
274274

275275

276-
def _get_handle(source, mode, encoding=None, compression=None,
276+
def _get_handle(path_or_buf, mode, encoding=None, compression=None,
277277
memory_map=False):
278278
"""
279279
Get file handle for given path/buffer and mode.
280280
"""
281281

282-
f = source
283-
is_path = isinstance(source, compat.string_types)
282+
f = path_or_buf
283+
is_path = isinstance(path_or_buf, compat.string_types)
284284

285285
# in Python 3, convert BytesIO or fileobjects passed with an encoding
286-
if compat.PY3 and isinstance(source, compat.BytesIO):
286+
if compat.PY3 and isinstance(path_or_buf, compat.BytesIO):
287287
from io import TextIOWrapper
288-
return TextIOWrapper(source, encoding=encoding)
288+
return TextIOWrapper(path_or_buf, encoding=encoding)
289289

290290
elif compression:
291291
compression = compression.lower()
292-
292+
293293
if compat.PY2 and not is_path and encoding:
294294
msg = 'compression with encoding is not yet supported in Python 2'
295295
raise ValueError(msg)
@@ -298,38 +298,38 @@ def _get_handle(source, mode, encoding=None, compression=None,
298298
if compression == 'gzip':
299299
import gzip
300300
if is_path:
301-
f = gzip.open(source, mode)
301+
f = gzip.open(path_or_buf, mode)
302302
else:
303-
f = gzip.GzipFile(fileobj=source)
303+
f = gzip.GzipFile(fileobj=path_or_buf)
304304

305305
# BZ Compression
306306
elif compression == 'bz2':
307307
import bz2
308308
if is_path:
309-
f = bz2.BZ2File(source, mode)
309+
f = bz2.BZ2File(path_or_buf, mode)
310310
elif compat.PY2:
311311
# Python 2's bz2 module can't take file objects, so have to
312312
# run through decompress manually
313-
f = StringIO(bz2.decompress(source.read()))
313+
f = StringIO(bz2.decompress(path_or_buf.read()))
314314
else:
315-
f = bz2.BZ2File(source)
315+
f = bz2.BZ2File(path_or_buf)
316316

317317
# ZIP Compression
318318
elif compression == 'zip':
319319
import zipfile
320-
zip_file = zipfile.ZipFile(source)
320+
zip_file = zipfile.ZipFile(path_or_buf)
321321
try:
322322
name, = zip_file.namelist()
323323
except ValueError:
324-
msg = 'Zip file must contain exactly one file {}'.format(source)
325-
raise ValueError(msg)
326-
f = zip_file.open(zip_names.pop())
324+
raise ValueError('Zip file must contain exactly one file {}'
325+
.format(path_or_buf))
326+
f = zip_file.open(name)
327327

328328
# XZ Compression
329329
elif compression == 'xz':
330330
lzma = compat.import_lzma()
331-
f = lzma.LZMAFile(source, mode)
332-
331+
f = lzma.LZMAFile(path_or_buf, mode)
332+
333333
# Unrecognized Compression
334334
else:
335335
msg = 'Unrecognized compression: {}'.format(compression)
@@ -345,13 +345,13 @@ def _get_handle(source, mode, encoding=None, compression=None,
345345
elif is_path:
346346
if compat.PY2:
347347
# Python 2
348-
f = open(source, mode)
348+
f = open(path_or_buf, mode)
349349
elif encoding:
350350
# Python 3 and encoding
351-
f = open(source, mode, encoding=encoding)
351+
f = open(path_or_buf, mode, encoding=encoding)
352352
else:
353353
# Python 3 and no explicit encoding
354-
f = open(source, mode, errors='replace')
354+
f = open(path_or_buf, mode, errors='replace')
355355

356356
if memory_map and hasattr(f, 'fileno'):
357357
try:

0 commit comments

Comments
 (0)