Skip to content

Commit b4e280f

Browse files
committed
Infer compression from non-string paths
1 parent a3b9ee9 commit b4e280f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: pandas/io/common.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,15 @@ def _infer_compression(filepath_or_buffer, compression):
272272
if compression is None:
273273
return None
274274

275-
# Cannot infer compression of a buffer. Hence assume no compression.
276-
is_path = isinstance(filepath_or_buffer, compat.string_types)
277-
if compression == 'infer' and not is_path:
278-
return None
279-
280-
# Infer compression from the filename/URL extension
275+
# Infer compression
281276
if compression == 'infer':
277+
# Convert all path types (e.g. pathlib.Path) to strings
278+
filepath_or_buffer = _stringify_path(filepath_or_buffer)
279+
if not isinstance(filepath_or_buffer, compat.string_types):
280+
# Cannot infer compression of a buffer, assume no compression
281+
return None
282+
283+
# Infer compression from the filename/URL extension
282284
for compression, extension in _compression_to_extension.items():
283285
if filepath_or_buffer.endswith(extension):
284286
return compression

0 commit comments

Comments
 (0)