Skip to content

Commit e3d4d9a

Browse files
committed
1 parent 5272b9e commit e3d4d9a

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

doc/source/whatsnew/v0.21.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Other Enhancements
126126
- :func:`date_range` now accepts 'Y' in addition to 'A' as an alias for end of year (:issue:`9313`)
127127
- Integration with `Apache Parquet <https://parquet.apache.org/>`__, including a new top-level :func:`read_parquet` and :func:`DataFrame.to_parquet` method, see :ref:`here <io.parquet>`.
128128
- :func:`DataFrame.add_prefix` and :func:`DataFrame.add_suffix` now accept strings containing the '%' character. (:issue:`17151`)
129-
- :func:`read_csv` can now infer compression from non-string paths, such as a ``pathlab.Path`` objects (:issue:`17206`).
129+
- :func:`read_csv` can now infer compression from non-string paths, such as a ``pathlib.Path`` objects (:issue:`17206`).
130130

131131
.. _whatsnew_0210.api_breaking:
132132

pandas/tests/io/parser/compression.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,17 @@ def test_read_csv_infer_compression(self):
157157

158158
inputs[3].close()
159159

160-
def test_read_csv_infer_compression_pathlib(self):
160+
@pytest.mark.parametrize('extension', ['', '.gz', '.bz2'])
161+
def test_read_csv_infer_compression_pathlib(self, extension):
161162
"""
162163
Test that compression is inferred from pathlib.Path paths.
163164
"""
164-
try:
165-
import pathlib
166-
except ImportError:
167-
pytest.skip('need pathlib to run')
168-
expected = self.read_csv(self.csv1, index_col=0, parse_dates=True)
169-
for extension in '', '.gz', '.bz2':
170-
path = pathlib.Path(self.csv1 + extension)
171-
df = self.read_csv(
172-
path, index_col=0, parse_dates=True, compression='infer')
173-
tm.assert_frame_equal(expected, df)
165+
pathlib = pytest.importorskip('pathlib')
166+
read_csv_kwargs = {'index_col': 0, 'parse_dates': True}
167+
expected = self.read_csv(self.csv1, **read_csv_kwargs)
168+
path = pathlib.Path(self.csv1 + extension)
169+
df = self.read_csv(path, compression='infer', **read_csv_kwargs)
170+
tm.assert_frame_equal(expected, df)
174171

175172
def test_invalid_compression(self):
176173
msg = 'Unrecognized compression type: sfark'

0 commit comments

Comments
 (0)