@@ -256,41 +256,38 @@ def test_compression_size_fh(obj, method, compression_only):
256
256
assert uncompressed > compressed
257
257
258
258
259
- @pytest .mark .parametrize ('write_method, read_method' , [
260
- ('to_csv' , pandas .read_csv ),
261
- ('to_json' , pandas .read_json ),
262
- ('to_pickle' , pandas .read_pickle ),
259
+ @pytest .mark .parametrize ('write_method, write_kwargs, read_method' , [
260
+ ('to_csv' , { 'index' : False }, pandas .read_csv ),
261
+ ('to_json' , {}, pandas .read_json ),
262
+ ('to_pickle' , {}, pandas .read_pickle ),
263
263
])
264
264
def test_dataframe_compression_defaults_to_infer (
265
- write_method , read_method , compression_only ):
265
+ write_method , write_kwargs , read_method , compression_only ):
266
266
# Test that DataFrame.to_* methods default to inferring compression from
267
267
# paths. https://github.com/pandas-dev/pandas/pull/22011
268
268
input = DataFrame ([[1.0 , 0 , - 4.4 ], [3.4 , 5 , 2.4 ]], columns = ['X' , 'Y' , 'Z' ])
269
269
extension = _compression_to_extension [compression_only ]
270
- kwargs = {}
271
- if write_method == 'to_csv' :
272
- kwargs ['index' ] = False
273
270
with tm .ensure_clean ('compressed' + extension ) as path :
274
271
# assumes that compression='infer' is the default
275
- getattr (input , write_method )(path , ** kwargs )
272
+ getattr (input , write_method )(path , ** write_kwargs )
276
273
output = read_method (path , compression = compression_only )
277
274
tm .assert_frame_equal (output , input )
278
275
279
276
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 ),
277
+ @pytest .mark .parametrize ('write_method, write_kwargs, read_method' , [
278
+ ('to_csv' , {}, pandas .Series .from_csv ),
279
+ ('to_json' , { 'typ' : 'series' }, pandas .read_json ),
280
+ ('to_pickle' , {}, pandas .read_pickle ),
284
281
])
285
282
def test_series_compression_defaults_to_infer (
286
- write_method , read_method , compression_only ):
283
+ write_method , write_kwargs , read_method , compression_only ):
287
284
# Test that Series.to_* methods default to inferring compression from
288
285
# paths. https://github.com/pandas-dev/pandas/pull/22011
289
286
input = Series (100 * [0 , 5 , - 2 , 10 ])
290
287
extension = _compression_to_extension [compression_only ]
291
288
with tm .ensure_clean ('compressed' + extension ) as path :
292
289
# assumes that compression='infer' is the default
293
- getattr (input , write_method )(path )
290
+ getattr (input , write_method )(path , ** write_kwargs )
294
291
output = read_method (path , compression = compression_only )
295
292
tm .assert_series_equal (output , input )
296
293
0 commit comments