| 240 | |
| 241 | |
| 242 | class ZarrArrayWrapper(BackendArray): |
| 243 | __slots__ = ("_array", "dtype", "shape") |
| 244 | |
| 245 | def __init__(self, zarr_array): |
| 246 | # some callers attempt to evaluate an array if an `array` property exists on the object. |
| 247 | # we prefix with _ to avoid this inference. |
| 248 | |
| 249 | # TODO type hint this? |
| 250 | self._array = zarr_array |
| 251 | self.shape = self._array.shape |
| 252 | |
| 253 | # preserve vlen string object dtype (GH 7328) |
| 254 | if ( |
| 255 | not _zarr_v3() |
| 256 | and self._array.filters is not None |
| 257 | and any(filt.codec_id == "vlen-utf8" for filt in self._array.filters) |
| 258 | ) or ( |
| 259 | _zarr_v3() |
| 260 | and self._array.serializer |
| 261 | and self._array.serializer.to_dict()["name"] == "vlen-utf8" |
| 262 | ): |
| 263 | dtype = coding.strings.create_vlen_dtype(str) |
| 264 | else: |
| 265 | dtype = self._array.dtype |
| 266 | |
| 267 | self.dtype = dtype |
| 268 | |
| 269 | def get_array(self): |
| 270 | return self._array |
| 271 | |
| 272 | def _oindex(self, key): |
| 273 | return self._array.oindex[key] |
| 274 | |
| 275 | def _vindex(self, key): |
| 276 | return self._array.vindex[key] |
| 277 | |
| 278 | def _getitem(self, key): |
| 279 | return self._array[key] |
| 280 | |
| 281 | async def _async_getitem(self, key): |
| 282 | if not _zarr_v3(): |
| 283 | raise NotImplementedError( |
| 284 | "For lazy basic async indexing with zarr, zarr-python=>v3.0.0 is required" |
| 285 | ) |
| 286 | |
| 287 | async_array = self._array._async_array |
| 288 | return await async_array.getitem(key) |
| 289 | |
| 290 | async def _async_oindex(self, key): |
| 291 | if not has_zarr_async_index(): |
| 292 | raise NotImplementedError( |
| 293 | "For lazy orthogonal async indexing with zarr, zarr-python=>v3.1.2 is required" |
| 294 | ) |
| 295 | |
| 296 | async_array = self._array._async_array |
| 297 | return await async_array.oindex.getitem(key) |
| 298 | |
| 299 | async def _async_vindex(self, key): |
no outgoing calls
no test coverage detected
searching dependent graphs…