Skip to content

Commit 1eb3dd7

Browse files
committed
Normalize internal helper and module names across blosc2
1 parent 493c805 commit 1eb3dd7

14 files changed

Lines changed: 124 additions & 123 deletions

src/blosc2/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class FPAccuracy(Enum):
253253
The C-Blosc2 version's string."""
254254

255255
if IS_WASM:
256-
from ._wasm_jit import init_wasm_jit_helpers
256+
from .wasm_jit import init_wasm_jit_helpers
257257

258258
_WASM_MINIEXPR_ENABLED = init_wasm_jit_helpers()
259259

@@ -538,7 +538,7 @@ def _raise(exc):
538538
from .batch_store import Batch, BatchStore
539539
from .vlarray import VLArray, vlarray_from_cframe
540540
from .ref import Ref
541-
from .b2objects import _open_b2object
541+
from .b2objects import open_b2object
542542

543543
from .c2array import c2context, C2Array, URLPath
544544

@@ -549,7 +549,7 @@ def _raise(exc):
549549
lazyexpr,
550550
LazyArray,
551551
LazyUDF,
552-
_open_lazyarray,
552+
open_lazyarray,
553553
get_expr_operands,
554554
validate_expr,
555555
evaluate,

src/blosc2/b2objects.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_B2OBJECT_DSL_VERSION = 1
2525

2626

27-
def _make_b2object_carrier(
27+
def make_b2object_carrier(
2828
kind: str,
2929
shape,
3030
dtype,
@@ -39,19 +39,19 @@ def _make_b2object_carrier(
3939
return blosc2.empty(shape=shape, dtype=dtype, chunks=chunks, blocks=blocks, **kwargs)
4040

4141

42-
def _write_b2object_payload(array, payload: dict[str, Any]) -> None:
42+
def write_b2object_payload(array, payload: dict[str, Any]) -> None:
4343
array.schunk.vlmeta[_B2OBJECT_META_KEY] = payload
4444

4545

46-
def _encode_operand_reference(obj):
46+
def encode_operand_reference(obj):
4747
return blosc2.Ref.from_object(obj).to_dict()
4848

4949

50-
def _decode_operand_reference(payload):
50+
def decode_operand_reference(payload):
5151
return blosc2.Ref.from_dict(payload).open()
5252

5353

54-
def _encode_b2object_payload(obj) -> dict[str, Any] | None:
54+
def encode_b2object_payload(obj) -> dict[str, Any] | None:
5555
if isinstance(obj, blosc2.C2Array):
5656
return blosc2.Ref.c2array_ref(obj.path, obj.urlbase).to_dict()
5757
if isinstance(obj, blosc2.LazyExpr):
@@ -61,7 +61,7 @@ def _encode_b2object_payload(obj) -> dict[str, Any] | None:
6161
"kind": "lazyexpr",
6262
"version": _B2OBJECT_VERSION,
6363
"expression": expression,
64-
"operands": {key: _encode_operand_reference(value) for key, value in operands.items()},
64+
"operands": {key: encode_operand_reference(value) for key, value in operands.items()},
6565
}
6666
if isinstance(obj, blosc2.LazyUDF):
6767
if not isinstance(obj.func, DSLKernel):
@@ -92,13 +92,13 @@ def _encode_b2object_payload(obj) -> dict[str, Any] | None:
9292
"dsl_source": obj.func.dsl_source,
9393
"dtype": np.dtype(obj.dtype).str,
9494
"shape": list(obj.shape),
95-
"operands": {f"o{i}": _encode_operand_reference(value) for i, value in enumerate(obj.inputs)},
95+
"operands": {f"o{i}": encode_operand_reference(value) for i, value in enumerate(obj.inputs)},
9696
"kwargs": kwargs,
9797
}
9898
return None
9999

100100

101-
def _decode_b2object_payload(payload: dict[str, Any]):
101+
def decode_b2object_payload(payload: dict[str, Any]):
102102
kind = payload.get("kind")
103103
version = payload.get("version")
104104
if version != _B2OBJECT_VERSION:
@@ -107,24 +107,24 @@ def _decode_b2object_payload(payload: dict[str, Any]):
107107
ref = blosc2.Ref.from_dict(payload)
108108
return ref.open()
109109
if kind == "lazyexpr":
110-
return _decode_structured_lazyexpr(payload)
110+
return decode_structured_lazyexpr(payload)
111111
if kind == "lazyudf":
112-
return _decode_structured_lazyudf(payload)
112+
return decode_structured_lazyudf(payload)
113113
raise ValueError(f"Unsupported persisted Blosc2 object kind: {kind!r}")
114114

115115

116-
def _decode_structured_lazyexpr(payload):
116+
def decode_structured_lazyexpr(payload):
117117
expression = payload.get("expression")
118118
if not isinstance(expression, str):
119119
raise TypeError("Structured LazyExpr payload requires a string 'expression'")
120120
operands_payload = payload.get("operands")
121121
if not isinstance(operands_payload, dict):
122122
raise TypeError("Structured LazyExpr payload requires a mapping 'operands'")
123-
operands = {key: _decode_operand_reference(value) for key, value in operands_payload.items()}
123+
operands = {key: decode_operand_reference(value) for key, value in operands_payload.items()}
124124
return blosc2.lazyexpr(expression, operands=operands)
125125

126126

127-
def _decode_structured_lazyudf(payload):
127+
def decode_structured_lazyudf(payload):
128128
function_kind = payload.get("function_kind")
129129
if function_kind != "dsl":
130130
raise ValueError(f"Unsupported structured LazyUDF function kind: {function_kind!r}")
@@ -167,31 +167,31 @@ def _decode_structured_lazyudf(payload):
167167
func.dsl_source = dsl_source
168168

169169
operands = tuple(
170-
_decode_operand_reference(operands_payload[f"o{n}"]) for n in range(len(operands_payload))
170+
decode_operand_reference(operands_payload[f"o{n}"]) for n in range(len(operands_payload))
171171
)
172172
return blosc2.lazyudf(func, operands, dtype=np.dtype(dtype), shape=tuple(shape_payload), **kwargs)
173173

174174

175-
def _read_b2object_marker(obj) -> dict[str, Any] | None:
175+
def read_b2object_marker(obj) -> dict[str, Any] | None:
176176
schunk = getattr(obj, "schunk", obj)
177177
if _B2OBJECT_META_KEY not in schunk.meta:
178178
return None
179179
return schunk.meta[_B2OBJECT_META_KEY]
180180

181181

182-
def _read_b2object_payload(obj) -> dict[str, Any]:
182+
def read_b2object_payload(obj) -> dict[str, Any]:
183183
schunk = getattr(obj, "schunk", obj)
184184
return schunk.vlmeta[_B2OBJECT_META_KEY]
185185

186186

187-
def _open_b2object(obj):
188-
marker = _read_b2object_marker(obj)
187+
def open_b2object(obj):
188+
marker = read_b2object_marker(obj)
189189
if marker is None:
190190
return None
191191

192-
payload = _read_b2object_payload(obj)
192+
payload = read_b2object_payload(obj)
193193
if marker.get("version") != _B2OBJECT_VERSION:
194194
raise ValueError(f"Unsupported persisted Blosc2 object version: {marker.get('version')!r}")
195195
if marker.get("kind") != payload.get("kind"):
196196
raise ValueError("Persisted Blosc2 object marker/payload kind mismatch")
197-
return _decode_b2object_payload(payload)
197+
return decode_b2object_payload(payload)

src/blosc2/blosc2_ext.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def destroy():
726726
blosc2_destroy()
727727

728728

729-
def _register_wasm_jit_helpers(uintptr_t instantiate_ptr, uintptr_t free_ptr):
729+
def register_wasm_jit_helpers(uintptr_t instantiate_ptr, uintptr_t free_ptr):
730730
cdef me_wasm_jit_instantiate_helper instantiate_helper = (
731731
<me_wasm_jit_instantiate_helper>instantiate_ptr
732732
)

src/blosc2/c2array.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import requests
1919

2020
import blosc2
21-
from blosc2.b2objects import _encode_b2object_payload, _make_b2object_carrier, _write_b2object_payload
21+
from blosc2.b2objects import encode_b2object_payload, make_b2object_carrier, write_b2object_payload
2222
from blosc2.info import InfoReporter, format_nbytes_info
2323

2424
_subscriber_data = {
@@ -240,13 +240,13 @@ def __init__(self, path: str, /, urlbase: str | None = None, auth_token: str | N
240240
self._cparams = blosc2.CParams(**cparams)
241241

242242
def _to_b2object_payload(self) -> dict:
243-
payload = _encode_b2object_payload(self)
243+
payload = encode_b2object_payload(self)
244244
if payload is None:
245245
raise TypeError("Unsupported persisted Blosc2 object")
246246
return payload
247247

248248
def _to_b2object_carrier(self, **kwargs):
249-
array = _make_b2object_carrier(
249+
array = make_b2object_carrier(
250250
"c2array",
251251
self.shape,
252252
self.dtype,
@@ -255,7 +255,7 @@ def _to_b2object_carrier(self, **kwargs):
255255
cparams=self.cparams,
256256
**kwargs,
257257
)
258-
_write_b2object_payload(array, self._to_b2object_payload())
258+
write_b2object_payload(array, self._to_b2object_payload())
259259
return array
260260

261261
def to_cframe(self) -> bytes:

src/blosc2/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ def from_cframe(
19591959
if "vlarray" in schunk.meta:
19601960
return blosc2.vlarray_from_cframe(cframe, copy=copy)
19611961
if "b2o" in schunk.meta:
1962-
return blosc2._open_b2object(ndarray_from_cframe(cframe, copy=copy))
1962+
return blosc2.open_b2object(ndarray_from_cframe(cframe, copy=copy))
19631963
if "b2nd" in schunk.meta:
19641964
return ndarray_from_cframe(cframe, copy=copy)
19651965
return schunk_from_cframe(cframe, copy=copy)

src/blosc2/dict_store.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import blosc2
2020
from blosc2.c2array import C2Array
2121
from blosc2.embed_store import EmbedStore
22-
from blosc2.schunk import SChunk, _process_opened_object
22+
from blosc2.schunk import SChunk, process_opened_object
2323

2424
if TYPE_CHECKING:
2525
from collections.abc import Iterator, Set
@@ -227,7 +227,7 @@ def _opened_external_kind(
227227
rel_path: str,
228228
) -> str | None:
229229
"""Return the supported external leaf kind for an already opened object."""
230-
processed = _process_opened_object(opened)
230+
processed = process_opened_object(opened)
231231
if isinstance(processed, blosc2.BatchStore):
232232
kind = "batchstore"
233233
elif isinstance(processed, blosc2.VLArray):
@@ -425,7 +425,7 @@ def __getitem__(
425425
mmap_mode=self.mmap_mode,
426426
dparams=self.dparams,
427427
)
428-
return self._annotate_external_value(key, _process_opened_object(opened))
428+
return self._annotate_external_value(key, process_opened_object(opened))
429429
else:
430430
urlpath = os.path.join(self.working_dir, filepath)
431431
if os.path.exists(urlpath):
@@ -501,7 +501,7 @@ def values(self) -> Iterator[blosc2.NDArray | SChunk | C2Array]:
501501
offset = self.offsets[filepath]["offset"]
502502
yield self._annotate_external_value(
503503
key,
504-
_process_opened_object(
504+
process_opened_object(
505505
blosc2.blosc2_ext.open(
506506
self.b2z_path,
507507
mode="r",
@@ -541,7 +541,7 @@ def items(self) -> Iterator[tuple[str, blosc2.NDArray | SChunk | C2Array]]:
541541
key,
542542
self._annotate_external_value(
543543
key,
544-
_process_opened_object(
544+
process_opened_object(
545545
blosc2.blosc2_ext.open(
546546
self.b2z_path,
547547
mode="r",

src/blosc2/dsl_kernel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def specialize_dsl_miniexpr_inputs(expr_string: str, operands: dict):
257257
return specialize_miniexpr_inputs(expr_string, operands)
258258

259259

260-
class _DSLValidator:
260+
class DSLValidator:
261261
_binop_map: ClassVar[dict[type[ast.operator], str]] = {
262262
ast.Add: "+",
263263
ast.Sub: "-",
@@ -526,7 +526,7 @@ def _extract_dsl(self, func, validate: bool = True):
526526
if dsl_func is None:
527527
raise ValueError("No function definition found in sliced DSL source")
528528
if validate:
529-
_DSLValidator(dsl_source).validate(dsl_func)
529+
DSLValidator(dsl_source).validate(dsl_func)
530530
input_names = self._input_names_from_signature(dsl_func)
531531
if _PRINT_DSL_KERNEL:
532532
func_name = getattr(func, "__name__", "<dsl_kernel>")
@@ -613,7 +613,7 @@ def validate_dsl(func):
613613
}
614614

615615

616-
class _DSLBuilder:
616+
class DSLBuilder:
617617
_binop_map: ClassVar[dict[type[ast.operator], str]] = {
618618
ast.Add: "+",
619619
ast.Sub: "-",
@@ -852,9 +852,9 @@ def _cmpop(self, op: ast.cmpop) -> str:
852852
raise ValueError("Unsupported comparison in DSL")
853853

854854

855-
class _DSLReducer:
856-
_binop_map: ClassVar[dict[type[ast.operator], str]] = _DSLBuilder._binop_map
857-
_cmp_map: ClassVar[dict[type[ast.cmpop], str]] = _DSLBuilder._cmp_map
855+
class DSLReducer:
856+
_binop_map: ClassVar[dict[type[ast.operator], str]] = DSLBuilder._binop_map
857+
_cmp_map: ClassVar[dict[type[ast.cmpop], str]] = DSLBuilder._cmp_map
858858

859859
def __init__(self, max_unroll: int = 64):
860860
self._env: dict[str, str] = {}

0 commit comments

Comments
 (0)