Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
60ab57f
Define the blosc2 namespace
FrancescAlted Aug 22, 2025
1af8a67
Add blosc2 dtypes (mirroring numpy dtypes)
FrancescAlted Aug 22, 2025
45daad0
Make asarray() accept scalars
FrancescAlted Aug 22, 2025
86be75d
Add entry points to toml
Aug 22, 2025
b6ec50d
Add iinfo
Aug 22, 2025
4edbace
Implemented __array_namespace_info__ and finfo
FrancescAlted Aug 22, 2025
c01ae3d
Add missing isnan and isfinite
FrancescAlted Aug 22, 2025
1340998
Add file for excluding tests with pytest --xfails-file
FrancescAlted Aug 22, 2025
d10b136
Instructions on how to run the Array API tests
FrancescAlted Aug 22, 2025
dbc81b5
A bit better docs
FrancescAlted Aug 22, 2025
44cea32
Adding None indexing
Aug 24, 2025
6c30b1b
Merge branch 'array-api' of github.com:Blosc/python-blosc2 into array…
Aug 26, 2025
271ff7e
Adding isnan/isfinite and other fixes for array-api getitem
lshaw8317 Aug 29, 2025
dd7c673
Fixing lazyexprs with no blosc2 operands
lshaw8317 Aug 29, 2025
d1b9ae3
Merge with main
lshaw8317 Sep 1, 2025
f82ac52
Fix failing blosc2 tests
lshaw8317 Sep 1, 2025
407aa21
Add negative step support
lshaw8317 Sep 1, 2025
5b16a66
First fixes for setitem, need to fix get_flatter_slices
lshaw8317 Sep 1, 2025
6186d74
Add support for negative steps for setitem
lshaw8317 Sep 2, 2025
b633abf
Fix small off-by-one error
lshaw8317 Sep 2, 2025
9e0cc93
Add setitem test
lshaw8317 Sep 2, 2025
3a85376
Now passes setitem tests for negative steps
lshaw8317 Sep 3, 2025
6028669
Added fancy indexing with slices with negative steps
lshaw8317 Sep 3, 2025
5e00ba5
Add setitem tests and resolve comments
lshaw8317 Sep 3, 2025
b4a2add
Further fixes for setitem
lshaw8317 Sep 3, 2025
0827b10
Now passes all setitem tests
lshaw8317 Sep 3, 2025
fdb9957
Fixes for chunks with zeros
lshaw8317 Sep 3, 2025
fbd3b06
Working on get/setitem masking
lshaw8317 Sep 3, 2025
d66afc4
Fixes to setitem for 0 chunks
lshaw8317 Sep 5, 2025
44dac9e
Add dtype conversion methods to Operand
lshaw8317 Sep 5, 2025
9282a91
Added astype function
lshaw8317 Sep 5, 2025
84b975c
Last fixes for ndarray_object array_api tests
lshaw8317 Sep 8, 2025
578d234
Small typo
lshaw8317 Sep 8, 2025
802c860
No (easy) optimisation for booleans possible. Now pass all ndarray_ob…
lshaw8317 Sep 9, 2025
e34aef0
Adding creation functions, remedy arange, add constants
lshaw8317 Sep 9, 2025
325c3e2
Adjust arange for backwards compatibility
lshaw8317 Sep 10, 2025
9e973ec
Fix numerical stability of linspace, add __bool__ for LazyExpr
lshaw8317 Sep 10, 2025
630d437
Fixes to linspace and optimization of arange
lshaw8317 Sep 10, 2025
d6975a1
Fixes to linspace and optimization of arange
lshaw8317 Sep 10, 2025
09d8f29
Fixes to arange
lshaw8317 Sep 10, 2025
f9e97aa
Various final fixes
lshaw8317 Sep 10, 2025
102b4a1
Bump numexpr version requirement
lshaw8317 Sep 10, 2025
019be81
Merge branch 'main' into array-api
lshaw8317 Sep 11, 2025
c0a65f5
Fix precommit error
lshaw8317 Sep 11, 2025
fb00e65
Apply pre-commit fixes
pre-commit-ci[bot] Sep 11, 2025
f99b298
Bump numexpr version to support complex isnan etc.
lshaw8317 Sep 11, 2025
41ef491
Merge branch 'array-api' of github.com:Blosc/python-blosc2 into array…
lshaw8317 Sep 11, 2025
30422a1
Passing inspection_functions tests
lshaw8317 Sep 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README_DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ We are using Sphinx for documentation. You can build the documentation by execu
[You may need to install the `pandoc` package first: https://pandoc.org/installing.html]

You will find the documentation in the `../html` directory.

## Array API tests compatibility

You can test array API compatibility with the `array-api-tests` module.
Use the `tests/array-api-xfails.txt` to skip the tests that are not supported
and run pytest from the `array-api-tests` source dir like this:

``` bash
ARRAY_API_TESTS_MODULE=blosc2 pytest array_api_tests --xfails-file ${BLOSC2_DIR}/tests/array-api-xfails.txt -xs
```
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ dependencies = [
"ndindex",
"msgpack",
"platformdirs",
"numexpr; platform_machine != 'wasm32'",
"numexpr>=2.12.1; platform_machine != 'wasm32'",
"py-cpuinfo; platform_machine != 'wasm32'",
"requests",
]
version = "3.7.3.dev0"
[project.entry-points."array_api"]
blosc2 = "blosc2"


[project.optional-dependencies]
Expand Down Expand Up @@ -99,8 +101,6 @@ exclude = ["bench*", ".github*"]

[tool.ruff]
line-length = 109
# Raise complexity from the default 10 to 13
complexity = 13
extend-exclude = ["bench"]

[tool.ruff.lint]
Expand All @@ -116,7 +116,7 @@ extend-select = [
"SIM",
"TC",
"UP",
]
"C901"] # enable complexity rule
ignore = [
"B028",
"PT011",
Expand All @@ -130,3 +130,7 @@ ignore = [

[tool.ruff.lint.extend-per-file-ignores]
"tests/**" = ["F841"]

[tool.ruff.lint.mccabe]
# Raise complexity from the default 10 to 13
max-complexity = 13
132 changes: 129 additions & 3 deletions src/blosc2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import platform
from enum import Enum

import numpy as np

# Do the platform check once at module level
IS_WASM = platform.machine() == "wasm32"
# IS_WASM = True # for testing (comment this line out for production)
Expand All @@ -23,9 +25,10 @@
if not IS_WASM:
import numexpr

from .version import __version__
from .version import __array_api_version__, __version__

__version__ = __version__
__array_api_version__ = __array_api_version__
"""
Python-Blosc2 version.
"""
Expand Down Expand Up @@ -164,6 +167,94 @@ class Tuner(Enum):
"""
The C-Blosc2 version's string."""


# For array-api compatibility
iinfo = np.iinfo
finfo = np.finfo

# dtypes for array-api
str_ = np.str_
bytes_ = np.bytes_
object_ = np.object_

from numpy import (
bool_,
complex64,
complex128,
e,
euler_gamma,
float16,
float32,
float64,
inf,
int8,
int16,
int32,
int64,
nan,
newaxis,
pi,
uint8,
uint16,
uint32,
uint64,
)

DEFAULT_COMPLEX = complex128
"""
Default complex floating dtype."""

DEFAULT_FLOAT = float64
"""
Default real floating dtype."""

DEFAULT_INT = int64
"""
Default integer dtype."""

DEFAULT_INDEX = int64
"""
Default indexing dtype."""


class Info:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)


def __array_namespace_info__() -> Info:
"""
Return information about the array namespace following the Array API specification.
"""

def _raise(exc):
raise exc

return Info(
capabilities=lambda: {
"boolean indexing": True,
"data-dependent shapes": False,
"max dimensions": MAX_DIM,
},
default_device=lambda: "cpu",
default_dtypes=lambda device=None: {
"real floating": DEFAULT_FLOAT,
"complex floating": DEFAULT_COMPLEX,
"integral": DEFAULT_INT,
"indexing": DEFAULT_INDEX,
}
if (device == "cpu" or device is None)
else _raise(ValueError("Only cpu devices allowed")),
dtypes=lambda device=None, kind=None: np.__array_namespace_info__().dtypes(kind=kind, device=device)
if (device == "cpu" or device is None)
else _raise(ValueError("Only cpu devices allowed")),
devices=lambda: ["cpu"],
name="blosc2",
version=__version__,
)


# Public API for container module
from .core import (
clib_info,
Expand Down Expand Up @@ -237,9 +328,11 @@ class Tuner(Enum):
are_partitions_aligned,
are_partitions_behaved,
arange,
broadcast_to,
linspace,
eye,
asarray,
astype,
indices,
sort,
reshape,
Expand All @@ -248,14 +341,19 @@ class Tuner(Enum):
concatenate,
expand_dims,
empty,
empty_like,
frombuffer,
fromiter,
get_slice_nchunks,
meshgrid,
nans,
uninit,
zeros,
zeros_like,
ones,
ones_like,
full,
full_like,
save,
matmul,
permute_dims,
Expand All @@ -278,6 +376,7 @@ class Tuner(Enum):
get_expr_operands,
validate_expr,
evaluate,
slices_eval,
)
from .proxy import Proxy, ProxySource, ProxyNDSource, ProxyNDField, SimpleProxy, jit

Expand Down Expand Up @@ -333,9 +432,13 @@ class Tuner(Enum):
contains,
cos,
cosh,
equal,
exp,
expm1,
imag,
isfinite,
isinf,
isnan,
lazywhere,
log,
log1p,
Expand All @@ -356,14 +459,25 @@ class Tuner(Enum):
where,
)

__all__ = [
__all__ = [ # noqa : RUF022
# Constants
"EXTENDED_HEADER_LENGTH",
"MAX_BUFFERSIZE",
"MAX_TYPESIZE",
"MIN_HEADER_LENGTH",
"VERSION_DATE",
"VERSION_STRING",
# Default dtypes
"DEFAULT_COMPLEX",
"DEFAULT_FLOAT",
"DEFAULT_INDEX",
"DEFAULT_INT",
# Mathematical constants
"e",
"pi",
"inf",
"nan",
"newaxis",
# Classes
"C2Array",
"CParams",
Expand Down Expand Up @@ -407,7 +521,8 @@ class Tuner(Enum):
"are_partitions_aligned",
"are_partitions_behaved",
"asarray",
"clib_info",
"astypeclib_info",
"broadcast_to",
"compress",
"compress2",
"compressor_list",
Expand All @@ -421,6 +536,9 @@ class Tuner(Enum):
"decompress2",
"detect_number_of_cores",
"dparams_dflts",
"empty",
"empty_like",
"equal",
"estore_from_cframe",
"expand_dims",
"expm1",
Expand All @@ -430,6 +548,7 @@ class Tuner(Enum):
"frombuffer",
"fromiter",
"full",
"full_like",
"get_blocksize",
"get_cbuffer_sizes",
"get_clib",
Expand All @@ -438,6 +557,9 @@ class Tuner(Enum):
"get_expr_operands",
"get_slice_nchunks",
"indices",
"isfinite",
"isinf",
"isnan",
"jit",
"lazyexpr",
"lazyudf",
Expand All @@ -452,10 +574,12 @@ class Tuner(Enum):
"matrix_transpose",
"max",
"mean",
"meshgrid",
"min",
"nans",
"ndarray_from_cframe",
"ones",
"ones_like",
"open",
"pack",
"pack_array",
Expand Down Expand Up @@ -494,4 +618,6 @@ class Tuner(Enum):
"validate_expr",
"var",
"where",
"zeros",
"zeros_like",
]
4 changes: 2 additions & 2 deletions src/blosc2/blosc2_ext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2612,8 +2612,8 @@ cdef class NDArray:
mask_[i] = mask[i]
_check_rc(b2nd_squeeze_index(self.array, mask_), "Error while squeezing array")

if self.array.shape[0] == 1 and self.ndim == 1:
self.array.ndim = 0
#if self.array.shape[0] == 1 and self.ndim == 1:
# self.array.ndim = 0
Comment thread
lshaw8317 marked this conversation as resolved.

def as_ffi_ptr(self):
return PyCapsule_New(self.array, <char *> "b2nd_array_t*", NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/blosc2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ def compute_chunks_blocks( # noqa: C901

# Return an arbitrary value for chunks and blocks when shape has any 0 dim
if 0 in shape:
return (1,) * len(shape), (1,) * len(shape)
return shape, shape

if blocks:
if not isinstance(blocks, tuple | list):
Expand Down
Loading
Loading