| 
1 | 1 | from __future__ import annotations  | 
2 | 2 | 
 
  | 
 | 3 | +import mmap  | 
3 | 4 | from typing import TYPE_CHECKING  | 
4 | 5 | 
 
  | 
5 |  | -import mmap  | 
6 | 6 | import pytest  | 
7 | 7 | 
 
  | 
8 | 8 | import zarr  | 
 | 
15 | 15 | 
 
  | 
16 | 16 | 
 
  | 
17 | 17 | class MemoryMappedDirectoryStore(LocalStore):  | 
18 |  | -    def _fromfile(self, fn):  | 
 | 18 | +    def _fromfile(self, fn: str) -> memoryview:  | 
19 | 19 |         with open(fn, "rb") as fh:  | 
20 | 20 |             return memoryview(mmap.mmap(fh.fileno(), 0, prot=mmap.PROT_READ))  | 
21 | 21 | 
 
  | 
@@ -64,22 +64,20 @@ def test_creates_new_directory(self, tmp_path: pathlib.Path):  | 
64 | 64 |     async def test_mmap_slice_reads(self, store: MemoryMappedDirectoryStore) -> None:  | 
65 | 65 |         """Test reading slices with memory mapping"""  | 
66 | 66 |         # Create array with large chunks  | 
67 |  | -        z = zarr.create_array(store=store, shape=(2000, 2000), chunks=(1000, 1000),   | 
68 |  | -                            dtype='float64')  | 
 | 67 | +        z = zarr.create_array(store=store, shape=(2000, 2000), chunks=(1000, 1000), dtype="float64")  | 
69 | 68 |         # Write test data  | 
70 |  | -        data = zarr.full(shape=(2000, 2000), chunks=(1000, 1000), fill_value=42.0,   | 
71 |  | -                        dtype='float64')  | 
 | 69 | +        data = zarr.full(shape=(2000, 2000), chunks=(1000, 1000), fill_value=42.0, dtype="float64")  | 
72 | 70 |         z[:] = data[:]  | 
73 |  | -          | 
 | 71 | + | 
74 | 72 |         # Test reading various slices  | 
75 | 73 |         slices = [  | 
76 | 74 |             # Within single chunk  | 
77 | 75 |             (slice(100, 200), slice(100, 200)),  | 
78 | 76 |             # Across chunk boundaries  | 
79 | 77 |             (slice(900, 1100), slice(900, 1100)),  | 
80 | 78 |             # Full chunk  | 
81 |  | -            (slice(0, 1000), slice(0, 1000))  | 
 | 79 | +            (slice(0, 1000), slice(0, 1000)),  | 
82 | 80 |         ]  | 
83 |  | -          | 
 | 81 | + | 
84 | 82 |         for test_slice in slices:  | 
85 | 83 |             assert (z[test_slice] == data[test_slice]).all()  | 
0 commit comments