Skip to content

Commit b860ffe

Browse files
committed
1 parent 3432915 commit b860ffe

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
@@ -166,20 +166,17 @@ def test_read_csv_infer_compression(self):
166166

167167
inputs[3].close()
168168

169-
def test_read_csv_infer_compression_pathlib(self):
169+
@pytest.mark.parametrize('extension', ['', '.gz', '.bz2'])
170+
def test_read_csv_infer_compression_pathlib(self, extension):
170171
"""
171172
Test that compression is inferred from pathlib.Path paths.
172173
"""
173-
try:
174-
import pathlib
175-
except ImportError:
176-
pytest.skip('need pathlib to run')
177-
expected = self.read_csv(self.csv1, index_col=0, parse_dates=True)
178-
for extension in '', '.gz', '.bz2':
179-
path = pathlib.Path(self.csv1 + extension)
180-
df = self.read_csv(
181-
path, index_col=0, parse_dates=True, compression='infer')
182-
tm.assert_frame_equal(expected, df)
174+
pathlib = pytest.importskip('pathlib')
175+
read_csv_kwargs = {'index_col': 0, 'parse_dates': True}
176+
expected = self.read_csv(self.csv1, **read_csv_kwargs)
177+
path = pathlib.Path(self.csv1 + extension)
178+
df = self.read_csv(path, compression='infer', **read_csv_kwargs)
179+
tm.assert_frame_equal(expected, df)
183180

184181
def test_invalid_compression(self):
185182
msg = 'Unrecognized compression type: sfark'

0 commit comments

Comments
 (0)