Skip to content

Commit be41f85

Browse files
committed
More consistent naming
1 parent afc8436 commit be41f85

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/blosc2/batch_store.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ def _check_serialized_size(buffer: bytes) -> None:
2727

2828

2929
class Batch(Sequence[Any]):
30-
"""A lazy sequence of Python objects stored in one BatchStore chunk."""
30+
"""A lazy sequence of Python objects stored in one BatchStore batch."""
3131

32-
def __init__(self, parent: BatchStore, nchunk: int, lazychunk: bytes) -> None:
32+
def __init__(self, parent: BatchStore, nbatch: int, lazybatch: bytes) -> None:
3333
self._parent = parent
34-
self._nchunk = nchunk
35-
self._lazychunk = lazychunk
34+
self._nbatch = nbatch
35+
self._lazybatch = lazybatch
3636
self._blocks: list[list[Any]] | None = None
37-
self._nbytes, self._cbytes, self._nblocks = blosc2.get_cbuffer_sizes(lazychunk)
37+
self._nbytes, self._cbytes, self._nblocks = blosc2.get_cbuffer_sizes(lazybatch)
3838

3939
def _normalize_index(self, index: int) -> int:
4040
if not isinstance(index, int):
@@ -47,7 +47,7 @@ def _normalize_index(self, index: int) -> int:
4747

4848
def _decode_blocks(self) -> list[list[Any]]:
4949
if self._blocks is None:
50-
self._blocks = self._parent._decode_blocks(self._nchunk)
50+
self._blocks = self._parent._decode_blocks(self._nbatch)
5151
return self._blocks
5252

5353
def __getitem__(self, index: int | slice) -> Any | list[Any]:
@@ -73,8 +73,8 @@ def __iter__(self) -> Iterator[Any]:
7373
yield self[i]
7474

7575
@property
76-
def lazychunk(self) -> bytes:
77-
return self._lazychunk
76+
def lazybatch(self) -> bytes:
77+
return self._lazybatch
7878

7979
@property
8080
def nbytes(self) -> int:
@@ -338,9 +338,9 @@ def _compress_batch(self, batch: list[Any]) -> bytes:
338338
]
339339
return blosc2.blosc2_ext.vlcompress(blocks, **self._vl_cparams_kwargs())
340340

341-
def _decode_blocks(self, nchunk: int) -> list[list[Any]]:
341+
def _decode_blocks(self, nbatch: int) -> list[list[Any]]:
342342
block_payloads = blosc2.blosc2_ext.vldecompress(
343-
self.schunk.get_chunk(nchunk), **self._vl_dparams_kwargs()
343+
self.schunk.get_chunk(nbatch), **self._vl_dparams_kwargs()
344344
)
345345
return [msgpack_unpackb(payload) for payload in block_payloads]
346346

@@ -351,16 +351,16 @@ def append(self, value: object) -> int:
351351
"""Append one batch and return the new number of entries."""
352352
self._check_writable()
353353
batch = self._serialize_batch(value)
354-
chunk = self._compress_batch(batch)
355-
return self.schunk.append_chunk(chunk)
354+
batch_payload = self._compress_batch(batch)
355+
return self.schunk.append_chunk(batch_payload)
356356

357357
def insert(self, index: int, value: object) -> int:
358358
"""Insert one batch at ``index`` and return the new number of entries."""
359359
self._check_writable()
360360
index = self._normalize_insert_index(index)
361361
batch = self._serialize_batch(value)
362-
chunk = self._compress_batch(batch)
363-
return self.schunk.insert_chunk(index, chunk)
362+
batch_payload = self._compress_batch(batch)
363+
return self.schunk.insert_chunk(index, batch_payload)
364364

365365
def delete(self, index: int | slice) -> int:
366366
"""Delete the batch at ``index`` and return the new number of entries."""
@@ -387,8 +387,8 @@ def extend(self, values: object) -> None:
387387
self._check_writable()
388388
for value in values:
389389
batch = self._serialize_batch(value)
390-
chunk = self._compress_batch(batch)
391-
self.schunk.append_chunk(chunk)
390+
batch_payload = self._compress_batch(batch)
391+
self.schunk.append_chunk(batch_payload)
392392

393393
def clear(self) -> None:
394394
"""Remove all entries from the container."""
@@ -424,23 +424,23 @@ def __setitem__(self, index: int | slice, value: object) -> None:
424424
self.schunk.delete_chunk(idx)
425425
for offset, item in enumerate(values):
426426
batch = self._serialize_batch(item)
427-
chunk = self._compress_batch(batch)
428-
self.schunk.insert_chunk(start + offset, chunk)
427+
batch_payload = self._compress_batch(batch)
428+
self.schunk.insert_chunk(start + offset, batch_payload)
429429
return
430430
if len(values) != len(indices):
431431
raise ValueError(
432432
f"attempt to assign sequence of size {len(values)} to extended slice of size {len(indices)}"
433433
)
434434
for idx, item in zip(indices, values, strict=True):
435435
batch = self._serialize_batch(item)
436-
chunk = self._compress_batch(batch)
437-
self.schunk.update_chunk(idx, chunk)
436+
batch_payload = self._compress_batch(batch)
437+
self.schunk.update_chunk(idx, batch_payload)
438438
return
439439
self._check_writable()
440440
index = self._normalize_index(index)
441441
batch = self._serialize_batch(value)
442-
chunk = self._compress_batch(batch)
443-
self.schunk.update_chunk(index, chunk)
442+
batch_payload = self._compress_batch(batch)
443+
self.schunk.update_chunk(index, batch_payload)
444444

445445
def __delitem__(self, index: int | slice) -> None:
446446
self.delete(index)

tests/test_batch_store.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_batchstore_roundtrip(contiguous, urlpath):
5858
assert len(batch0) == len(BATCHES[0])
5959
assert batch0[1] == BATCHES[0][1]
6060
assert batch0[:] == BATCHES[0]
61-
assert isinstance(batch0.lazychunk, bytes)
61+
assert isinstance(batch0.lazybatch, bytes)
6262
assert batch0.nbytes > 0
6363
assert batch0.cbytes > 0
6464
assert batch0.cratio > 0
@@ -216,14 +216,14 @@ def test_vlcompress_small_blocks_roundtrip():
216216
]
217217
payloads = [msgpack_packb(value) for value in values]
218218

219-
chunk = blosc2.blosc2_ext.vlcompress(
219+
batch_payload = blosc2.blosc2_ext.vlcompress(
220220
payloads,
221221
codec=blosc2.Codec.ZSTD,
222222
clevel=5,
223223
typesize=1,
224224
nthreads=1,
225225
)
226-
out = blosc2.blosc2_ext.vldecompress(chunk, nthreads=1)
226+
out = blosc2.blosc2_ext.vldecompress(batch_payload, nthreads=1)
227227

228228
assert out == payloads
229229

0 commit comments

Comments
 (0)