|
10 | 10 |
|
11 | 11 | 3. Move the created pickle to "data/legacy_pickle/<version>" directory.
|
12 | 12 | """
|
| 13 | +from array import array |
13 | 14 | import bz2
|
14 | 15 | import datetime
|
15 | 16 | import functools
|
|
37 | 38 | get_lzma_file,
|
38 | 39 | is_platform_little_endian,
|
39 | 40 | )
|
| 41 | +from pandas.compat._compressors import flatten_buffer |
40 | 42 | from pandas.compat._optional import import_optional_dependency
|
41 | 43 | import pandas.util._test_decorators as td
|
42 | 44 |
|
@@ -105,6 +107,37 @@ def legacy_pickle(request, datapath):
|
105 | 107 | # ---------------------
|
106 | 108 | # tests
|
107 | 109 | # ---------------------
|
| 110 | + |
| 111 | + |
| 112 | +@pytest.mark.parametrize( |
| 113 | + "data", |
| 114 | + [ |
| 115 | + b"123", |
| 116 | + b"123456", |
| 117 | + bytearray(b"123"), |
| 118 | + memoryview(b"123"), |
| 119 | + pickle.PickleBuffer(b"123"), |
| 120 | + array("I", [1, 2, 3]), |
| 121 | + memoryview(b"123456").cast("B", (3, 2)), |
| 122 | + memoryview(b"123456").cast("B", (3, 2))[::2], |
| 123 | + np.arange(12).reshape((3, 4), order="C"), |
| 124 | + np.arange(12).reshape((3, 4), order="F"), |
| 125 | + np.arange(12).reshape((3, 4), order="C")[:, ::2], |
| 126 | + ], |
| 127 | +) |
| 128 | +def test_flatten_buffer(data): |
| 129 | + result = flatten_buffer(data) |
| 130 | + expected = memoryview(data).tobytes("A") |
| 131 | + assert result == expected |
| 132 | + if isinstance(data, (bytes, bytearray)): |
| 133 | + assert result is data |
| 134 | + elif isinstance(result, memoryview): |
| 135 | + assert result.ndim == 1 |
| 136 | + assert result.format == "B" |
| 137 | + assert result.contiguous |
| 138 | + assert result.shape == (result.nbytes,) |
| 139 | + |
| 140 | + |
108 | 141 | def test_pickles(legacy_pickle):
|
109 | 142 | if not is_platform_little_endian():
|
110 | 143 | pytest.skip("known failure on non-little endian")
|
|
0 commit comments