@@ -256,28 +256,43 @@ def test_compression_size_fh(obj, method, compression_only):
256
256
assert uncompressed > compressed
257
257
258
258
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' , [
265
260
('to_csv' , pandas .read_csv ),
266
261
('to_json' , pandas .read_json ),
267
262
('to_pickle' , pandas .read_pickle ),
268
263
])
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 ])
273
290
extension = _compression_to_extension [compression_only ]
274
291
with tm .ensure_clean ('compressed' + extension ) as path :
275
292
# assumes that compression='infer' is the default
276
293
getattr (input , write_method )(path )
277
294
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 )
281
296
282
297
283
298
def test_compression_warning (compression_only ):
0 commit comments