Skip to content

Commit 1d5f22a

Browse files
committed
Add Index and CTableIndex classes to the sphinx docs
1 parent 9c6eb11 commit 1d5f22a

3 files changed

Lines changed: 105 additions & 10 deletions

File tree

doc/reference/ctable.rst

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,6 @@ snapshot that can be indexed like any other stored column. New rows inserted
240240
later via :meth:`CTable.append` or :meth:`CTable.extend` auto-fill omitted
241241
materialized-column values from the recorded expression metadata.
242242

243-
CTable indexes can also target **direct expressions** over stored columns via
244-
``create_index(expression=...)``. This lets queries reuse indexes for derived
245-
predicates without adding either a computed column or a materialized stored one.
246-
A matching ``FULL`` direct-expression index can also be reused by ordering paths
247-
such as :meth:`CTable.sort_by` when sorting by a computed column backed by the
248-
same expression. ``OPSI`` indexes are a separate exact-filtering tier with a
249-
tunable number of iterative ordering cycles; they are not intended to converge
250-
to a completely sorted ``FULL``/CSI index, so use ``FULL`` when globally sorted
251-
ordered reuse is required.
252-
253243
.. autosummary::
254244

255245
CTable.delete
@@ -271,6 +261,56 @@ ordered reuse is required.
271261
.. automethod:: CTable.rename_column
272262

273263

264+
Indexes
265+
-------
266+
267+
CTable indexes are created with :meth:`CTable.create_index` and returned as
268+
:class:`blosc2.ctable.CTableIndex` handles. A ``CTableIndex`` is the table
269+
counterpart to :class:`blosc2.Index`: it refers to an index stored in the table
270+
index catalog, and delegates maintenance operations such as ``drop()``,
271+
``rebuild()``, and ``compact()`` back to the owning table.
272+
273+
Indexes can target stored columns or **direct expressions** over stored columns
274+
via ``create_index(expression=...)``. This lets queries reuse indexes for
275+
derived predicates without adding either a computed column or a materialized
276+
stored one. A matching ``FULL`` direct-expression index can also be reused by
277+
ordering paths such as :meth:`CTable.sort_by` when sorting by a computed column
278+
backed by the same expression. ``OPSI`` indexes are a separate exact-filtering
279+
tier with a tunable number of iterative ordering cycles; they are not intended
280+
to converge to a completely sorted ``FULL``/CSI index, so use ``FULL`` when
281+
globally sorted ordered reuse is required.
282+
283+
.. autosummary::
284+
285+
CTable.create_index
286+
CTable.index
287+
CTable.indexes
288+
CTable.drop_index
289+
CTable.rebuild_index
290+
CTable.compact_index
291+
292+
.. automethod:: CTable.create_index
293+
.. automethod:: CTable.index
294+
.. autoattribute:: CTable.indexes
295+
.. automethod:: CTable.drop_index
296+
.. automethod:: CTable.rebuild_index
297+
.. automethod:: CTable.compact_index
298+
299+
.. autoclass:: blosc2.ctable.CTableIndex
300+
301+
.. autoattribute:: blosc2.ctable.CTableIndex.col_name
302+
.. autoattribute:: blosc2.ctable.CTableIndex.kind
303+
.. autoattribute:: blosc2.ctable.CTableIndex.stale
304+
.. autoattribute:: blosc2.ctable.CTableIndex.name
305+
.. autoattribute:: blosc2.ctable.CTableIndex.nbytes
306+
.. autoattribute:: blosc2.ctable.CTableIndex.cbytes
307+
.. autoattribute:: blosc2.ctable.CTableIndex.cratio
308+
.. automethod:: blosc2.ctable.CTableIndex.storage_stats
309+
.. automethod:: blosc2.ctable.CTableIndex.drop
310+
.. automethod:: blosc2.ctable.CTableIndex.rebuild
311+
.. automethod:: blosc2.ctable.CTableIndex.compact
312+
313+
274314
Persistence
275315
-----------
276316

doc/reference/index_class.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. _Index:
2+
3+
Index
4+
=====
5+
6+
Handle for an index attached to a :class:`~blosc2.NDArray`.
7+
8+
``Index`` objects are returned by NDArray indexing APIs such as
9+
:meth:`blosc2.NDArray.create_index`, :meth:`blosc2.NDArray.index`, and
10+
:attr:`blosc2.NDArray.indexes`. Use this handle to inspect index metadata and
11+
storage usage, or to drop, rebuild, and compact the index. Users normally do
12+
not instantiate ``Index`` directly.
13+
14+
For table indexes, see :class:`blosc2.ctable.CTableIndex`, documented in the
15+
:ref:`CTable` reference.
16+
17+
.. currentmodule:: blosc2
18+
19+
.. autoclass:: Index
20+
21+
.. autoattribute:: Index.descriptor
22+
.. autoattribute:: Index.kind
23+
.. autoattribute:: Index.field
24+
.. autoattribute:: Index.name
25+
.. autoattribute:: Index.target
26+
.. autoattribute:: Index.persistent
27+
.. autoattribute:: Index.stale
28+
.. autoattribute:: Index.nbytes
29+
.. autoattribute:: Index.cbytes
30+
.. autoattribute:: Index.cratio
31+
.. automethod:: Index.drop
32+
.. automethod:: Index.rebuild
33+
.. automethod:: Index.compact

src/blosc2/indexing.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,15 @@ def _component_cbytes(array: blosc2.NDArray, descriptor: dict, component: IndexC
40344034

40354035

40364036
class Index(Mapping):
4037+
"""Handle for an index attached to an :class:`blosc2.NDArray`.
4038+
4039+
``Index`` objects are returned by NDArray indexing helpers such as
4040+
:meth:`blosc2.NDArray.create_index`, :meth:`blosc2.NDArray.index`, and
4041+
:attr:`blosc2.NDArray.indexes`. They expose descriptor metadata and
4042+
convenience methods for dropping, rebuilding, or compacting the underlying
4043+
index. Users should not instantiate this class directly.
4044+
"""
4045+
40374046
def __init__(self, array: blosc2.NDArray, token: str):
40384047
self._array = array
40394048
self._token = token
@@ -4043,34 +4052,42 @@ def _descriptor(self) -> dict:
40434052

40444053
@property
40454054
def descriptor(self) -> dict:
4055+
"""Copy of the index descriptor dictionary."""
40464056
return _copy_descriptor_for_token(self._array, self._token)
40474057

40484058
@property
40494059
def kind(self) -> blosc2.IndexKind:
4060+
"""Kind of index, as an :class:`blosc2.IndexKind`."""
40504061
return blosc2.IndexKind(self._descriptor()["kind"])
40514062

40524063
@property
40534064
def field(self) -> str | None:
4065+
"""Structured-array field indexed by this handle, if any."""
40544066
return self._descriptor()["field"]
40554067

40564068
@property
40574069
def name(self) -> str | None:
4070+
"""Optional human-readable name assigned at creation time."""
40584071
return self._descriptor()["name"]
40594072

40604073
@property
40614074
def target(self) -> dict:
4075+
"""Descriptor of the indexed target."""
40624076
return self.descriptor["target"]
40634077

40644078
@property
40654079
def persistent(self) -> bool:
4080+
"""True when index sidecars are stored persistently on disk."""
40664081
return bool(self._descriptor()["persistent"])
40674082

40684083
@property
40694084
def stale(self) -> bool:
4085+
"""True if the index needs rebuilding before it can be reused."""
40704086
return bool(self._descriptor()["stale"])
40714087

40724088
@property
40734089
def nbytes(self) -> int:
4090+
"""Total uncompressed size in bytes for this index payload."""
40744091
descriptor = self._descriptor()
40754092
return sum(
40764093
_component_nbytes(self._array, descriptor, component)
@@ -4079,6 +4096,7 @@ def nbytes(self) -> int:
40794096

40804097
@property
40814098
def cbytes(self) -> int:
4099+
"""Total compressed size in bytes for this index payload."""
40824100
descriptor = self._descriptor()
40834101
return sum(
40844102
_component_cbytes(self._array, descriptor, component)
@@ -4087,19 +4105,23 @@ def cbytes(self) -> int:
40874105

40884106
@property
40894107
def cratio(self) -> float:
4108+
"""Compression ratio for this index payload."""
40904109
cbytes = self.cbytes
40914110
if cbytes == 0:
40924111
return math.inf
40934112
return self.nbytes / cbytes
40944113

40954114
def drop(self) -> None:
4115+
"""Drop this index and delete its sidecar payloads."""
40964116
drop_index(self._array, field=self.field, name=self.name)
40974117

40984118
def rebuild(self) -> Index:
4119+
"""Rebuild this index and return this handle."""
40994120
rebuild_index(self._array, field=self.field, name=self.name)
41004121
return self
41014122

41024123
def compact(self) -> Index:
4124+
"""Compact this index, merging incremental runs, and return this handle."""
41034125
compact_index(self._array, field=self.field, name=self.name)
41044126
return self
41054127

0 commit comments

Comments
 (0)