Skip to content

Commit fadb943

Browse files
committed
Split test_compression_defaults_to_infer into Series & DataFrame tests
1 parent 63e6591 commit fadb943

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

pandas/tests/test_common.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,28 +256,43 @@ def test_compression_size_fh(obj, method, compression_only):
256256
assert uncompressed > compressed
257257

258258

259-
@pytest.mark.parametrize('input', [
260-
DataFrame([[1.0, 0, -4.4],
261-
[3.4, 5, 2.4]], columns=['X', 'Y', 'Z']),
262-
Series([0, 1, 2, 4], name='X'),
263-
])
264-
@pytest.mark.parametrize('methods', [
259+
@pytest.mark.parametrize('write_method, read_method', [
265260
('to_csv', pandas.read_csv),
266261
('to_json', pandas.read_json),
267262
('to_pickle', pandas.read_pickle),
268263
])
269-
def test_compression_defaults_to_infer(input, methods, compression_only):
270-
# Test that to_* methods default to inferring compression from paths.
271-
# https://github.com/pandas-dev/pandas/pull/22011
272-
write_method, read_method = methods
264+
def test_dataframe_compression_defaults_to_infer(
265+
write_method, read_method, compression_only):
266+
# Test that DataFrame.to_* methods default to inferring compression from
267+
# paths. https://github.com/pandas-dev/pandas/pull/22011
268+
input = DataFrame([[1.0, 0, -4.4], [3.4, 5, 2.4]], columns=['X', 'Y', 'Z'])
269+
extension = _compression_to_extension[compression_only]
270+
kwargs = {}
271+
if write_method == 'to_csv':
272+
kwargs['index'] = False
273+
with tm.ensure_clean('compressed' + extension) as path:
274+
# assumes that compression='infer' is the default
275+
getattr(input, write_method)(path, **kwargs)
276+
output = read_method(path, compression=compression_only)
277+
tm.assert_frame_equal(output, input)
278+
279+
280+
@pytest.mark.parametrize('write_method, read_method', [
281+
('to_csv', pandas.Series.from_csv),
282+
('to_json', pandas.read_json),
283+
('to_pickle', pandas.read_pickle),
284+
])
285+
def test_series_compression_defaults_to_infer(
286+
write_method, read_method, compression_only):
287+
# Test that Series.to_* methods default to inferring compression from
288+
# paths. https://github.com/pandas-dev/pandas/pull/22011
289+
input = Series(100 * [0, 5, -2, 10])
273290
extension = _compression_to_extension[compression_only]
274291
with tm.ensure_clean('compressed' + extension) as path:
275292
# assumes that compression='infer' is the default
276293
getattr(input, write_method)(path)
277294
output = read_method(path, compression=compression_only)
278-
assert_equals = (tm.assert_frame_equal if isinstance(input, DataFrame)
279-
else tm.assert_series_equal)
280-
assert_equals(output, input)
295+
tm.assert_series_equal(output, input)
281296

282297

283298
def test_compression_warning(compression_only):

0 commit comments

Comments
 (0)