Skip to content

Commit 30422a1

Browse files
committed
Passing inspection_functions tests
1 parent 41ef491 commit 30422a1

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

src/blosc2/__init__.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
if not IS_WASM:
2626
import numexpr
2727

28-
from .version import __version__
28+
from .version import __array_api_version__, __version__
2929

3030
__version__ = __version__
31+
__array_api_version__ = __array_api_version__
3132
"""
3233
Python-Blosc2 version.
3334
"""
@@ -226,34 +227,28 @@ def __array_namespace_info__() -> Info:
226227
"""
227228
Return information about the array namespace following the Array API specification.
228229
"""
230+
231+
def _raise(exc):
232+
raise exc
233+
229234
return Info(
230-
capabilities={
235+
capabilities=lambda: {
231236
"boolean indexing": True,
232237
"data-dependent shapes": False,
233-
"max dimensions": 8,
238+
"max dimensions": MAX_DIM,
234239
},
235-
default_device=None,
236-
default_dtypes={
240+
default_device=lambda: "cpu",
241+
default_dtypes=lambda device=None: {
237242
"real floating": DEFAULT_FLOAT,
238243
"complex floating": DEFAULT_COMPLEX,
239244
"integral": DEFAULT_INT,
240245
"indexing": DEFAULT_INDEX,
241-
},
242-
dtypes={
243-
"bool": bool_,
244-
"int8": int8,
245-
"int16": int16,
246-
"int32": int32,
247-
"int64": int64,
248-
"uint8": uint8,
249-
"uint16": uint16,
250-
"uint32": uint32,
251-
"uint64": uint64,
252-
"float32": float32,
253-
"float64": float64,
254-
"complex64": complex64,
255-
"complex128": complex128,
256-
},
246+
}
247+
if (device == "cpu" or device is None)
248+
else _raise(ValueError("Only cpu devices allowed")),
249+
dtypes=lambda device=None, kind=None: np.__array_namespace_info__().dtypes(kind=kind, device=device)
250+
if (device == "cpu" or device is None)
251+
else _raise(ValueError("Only cpu devices allowed")),
257252
devices=lambda: ["cpu"],
258253
name="blosc2",
259254
version=__version__,

src/blosc2/ndarray.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,12 @@ def __complex__(self) -> complex:
991991
raise ValueError(f"Cannot convert array of shape {self.shape} to complex float.")
992992
return complex(self[()])
993993

994+
def item(self) -> float | bool | complex | int:
995+
"""
996+
Copy an element of an array to a standard Python scalar and return it.
997+
"""
998+
return self[()].item()
999+
9941000
@is_documented_by(sum)
9951001
def sum(self, axis=None, dtype=None, keepdims=False, **kwargs):
9961002
expr = blosc2.LazyExpr(new_op=(self, None, None))
@@ -1831,7 +1837,7 @@ def __setitem__( # noqa : C901
18311837

18321838
key_, mask = process_key(key, self.shape) # internally handles key an integer
18331839
if hasattr(value, "shape") and value.shape == ():
1834-
value = value[()]
1840+
value = value.item()
18351841

18361842
def updater(sel_idx):
18371843
return value[sel_idx]
@@ -4379,6 +4385,7 @@ def _check_ndarray_kwargs(**kwargs):
43794385
"storage",
43804386
"out",
43814387
]
4388+
_ = kwargs.pop("device", None) # pop device (not used, but needs to be discarded)
43824389
for key in kwargs:
43834390
if key not in supported_keys:
43844391
raise KeyError(

src/blosc2/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
__version__ = "3.7.3.dev0"
2+
__array_api_version__ = "2024.12"

0 commit comments

Comments
 (0)