Skip to content

Commit 4da8622

Browse files
authored
Infer compression if file extension is uppercase (#35164)
* Infer compression even if file extension is uppercase * Add upercase extensions to infer compression tests * Update whatsnew * Add PR number
1 parent d660810 commit 4da8622

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ I/O
10861086
- Bug in :meth:`~HDFStore.create_table` now raises an error when `column` argument was not specified in `data_columns` on input (:issue:`28156`)
10871087
- :meth:`read_json` now could read line-delimited json file from a file url while `lines` and `chunksize` are set.
10881088
- Bug in :meth:`DataFrame.to_sql` when reading DataFrames with ``-np.inf`` entries with MySQL now has a more explicit ``ValueError`` (:issue:`34431`)
1089+
- Bug where capitalised files extensions were not decompressed by read_* functions (:issue:`35164`)
10891090
- Bug in :meth:`read_excel` that was raising a ``TypeError`` when ``header=None`` and ``index_col`` given as list (:issue:`31783`)
10901091
- Bug in "meth"`read_excel` where datetime values are used in the header in a `MultiIndex` (:issue:`34748`)
10911092
- :func:`read_excel` no longer takes ``**kwds`` arguments. This means that passing in keyword ``chunksize`` now raises a ``TypeError`` (previously raised a ``NotImplementedError``), while passing in keyword ``encoding`` now raises a ``TypeError`` (:issue:`34464`)

pandas/io/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def infer_compression(
339339

340340
# Infer compression from the filename/URL extension
341341
for compression, extension in _compression_to_extension.items():
342-
if filepath_or_buffer.endswith(extension):
342+
if filepath_or_buffer.lower().endswith(extension):
343343
return compression
344344
return None
345345

pandas/tests/io/test_common.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ def test_stringify_path_fspath(self):
8787

8888
@pytest.mark.parametrize(
8989
"extension,expected",
90-
[("", None), (".gz", "gzip"), (".bz2", "bz2"), (".zip", "zip"), (".xz", "xz")],
90+
[
91+
("", None),
92+
(".gz", "gzip"),
93+
(".bz2", "bz2"),
94+
(".zip", "zip"),
95+
(".xz", "xz"),
96+
(".GZ", "gzip"),
97+
(".BZ2", "bz2"),
98+
(".ZIP", "zip"),
99+
(".XZ", "xz"),
100+
],
91101
)
92102
@pytest.mark.parametrize("path_type", path_types)
93103
def test_infer_compression_from_path(self, extension, expected, path_type):

0 commit comments

Comments
 (0)