| 350 | df.to_pickle(path, compression=compression) |
| 351 | |
| 352 | def test_write_infer(self, compression_ext, get_random_path, temp_file): |
| 353 | p1 = temp_file.parent / f"{temp_file.stem}{compression_ext}" |
| 354 | p2 = temp_file.parent / f"{temp_file.stem}.raw" |
| 355 | compression = self._extension_to_compression.get(compression_ext.lower()) |
| 356 | df = DataFrame( |
| 357 | 1.1 * np.arange(120).reshape((30, 4)), |
| 358 | columns=Index(list("ABCD"), dtype=object), |
| 359 | index=Index([f"i-{i}" for i in range(30)], dtype=object), |
| 360 | ) |
| 361 | |
| 362 | # write to compressed file by inferred compression method |
| 363 | df.to_pickle(p1) |
| 364 | |
| 365 | # decompress |
| 366 | with tm.decompress_file(p1, compression=compression) as f: |
| 367 | with open(p2, "wb") as fh: |
| 368 | fh.write(f.read()) |
| 369 | |
| 370 | # read decompressed file |
| 371 | df2 = pd.read_pickle(p2, compression=None) |
| 372 | |
| 373 | tm.assert_frame_equal(df, df2) |
| 374 | |
| 375 | def test_read_explicit(self, compression, get_random_path, temp_file): |
| 376 | p1 = temp_file.parent / f"{temp_file.stem}.raw" |