Skip to content

Commit 67ba26a

Browse files
committed
make BackendArray an ABC
1 parent 9b41e78 commit 67ba26a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

xarray/backends/common.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import time
66
import traceback
7+
from abc import ABC, abstractmethod
78
from collections.abc import Hashable, Iterable, Mapping, Sequence
89
from glob import glob
910
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, Union, overload
@@ -267,18 +268,22 @@ def robust_getitem(array, key, catch=Exception, max_retries=6, initial_delay=500
267268
time.sleep(1e-3 * next_delay)
268269

269270

270-
class BackendArray(NdimSizeLenMixin, indexing.ExplicitlyIndexed):
271+
class BackendArray(ABC, NdimSizeLenMixin, indexing.ExplicitlyIndexed):
271272
__slots__ = ()
272273

274+
@abstractmethod
275+
def __getitem__(key: indexing.ExplicitIndexer) -> np.typing.ArrayLike: ...
276+
277+
async def async_getitem(key: indexing.ExplicitIndexer) -> np.typing.ArrayLike:
278+
raise NotImplementedError("Backend does not not support asynchronous loading")
279+
273280
def get_duck_array(self, dtype: np.typing.DTypeLike = None):
274281
key = indexing.BasicIndexer((slice(None),) * self.ndim)
275282
return self[key] # type: ignore[index]
276283

277284
async def async_get_duck_array(self, dtype: np.typing.DTypeLike = None):
278285
key = indexing.BasicIndexer((slice(None),) * self.ndim)
279-
# TODO use zarr-python async get method here?
280-
print("async inside BackendArray")
281-
return await self.getitem(key) # type: ignore[index]
286+
return await self.async_getitem(key) # type: ignore[index]
282287

283288

284289
class AbstractDataStore:

0 commit comments

Comments
 (0)