MCPcopy Create free account
hub / github.com/PyTables/PyTables / _table__where_indexed

Function _table__where_indexed

tables/table.py:153–239  ·  view source on GitHub ↗
(
    self: Table,
    compiled: CompiledCondition,
    condition: str,
    condvars: dict[str, Column | np.ndarray],
    start: int,
    stop: int,
    step: int,
)

Source from the content-addressed store, hash-verified

151
152
153def _table__where_indexed(
154 self: Table,
155 compiled: CompiledCondition,
156 condition: str,
157 condvars: dict[str, Column | np.ndarray],
158 start: int,
159 stop: int,
160 step: int,
161) -> Iterator[tableextension.Row] | np.ndarray:
162 if profile:
163 tref = clock()
164 if profile:
165 show_stats("Entering table_whereIndexed", tref)
166 self._use_index = True
167 # Clean the table caches for indexed queries if needed
168 if self._dirtycache:
169 restorecache(self)
170
171 # Get the values in expression that are not columns
172 values = []
173 for key, value in condvars.items():
174 if isinstance(value, np.ndarray):
175 values.append((key, value.item()))
176 # Build a key for the sequence cache
177 seqkey = (condition, tuple(values), (start, stop, step))
178 # Do a lookup in sequential cache for this query
179 nslot = self._seqcache.getslot(seqkey)
180 if nslot >= 0:
181 # Get the row sequence from the cache
182 seq = self._seqcache.getitem(nslot)
183 if len(seq) == 0:
184 return iter([])
185 # seq is a list.
186 seq = np.array(seq, dtype="int64")
187 # Correct the ranges in cached sequence
188 if (start, stop, step) != (0, self.nrows, 1):
189 seq = seq[
190 (seq >= start) & (seq < stop) & ((seq - start) % step == 0)
191 ]
192 return self.itersequence(seq)
193 else:
194 # No luck. self._seqcache will be populated
195 # in the iterator if possible. (Row._finish_riterator)
196 self._seqcache_key = seqkey
197
198 # Compute the chunkmap for every index in indexed expression
199 idxexprs = compiled.index_expressions
200 strexpr = compiled.string_expression
201 cmvars = {}
202 tcoords = 0
203 for i, idxexpr in enumerate(idxexprs):
204 var, ops, lims = idxexpr
205 col = condvars[var]
206 index = col.index
207 assert index is not None, "the chosen column is not indexed"
208 assert not index.dirty, "the chosen column has a dirty index"
209
210 # Get the number of rows that the indexed condition yields.

Callers 1

_whereMethod · 0.85

Calls 8

restorecacheFunction · 0.85
itersequenceMethod · 0.80
get_lookup_rangeMethod · 0.80
searchMethod · 0.80
get_chunkmapMethod · 0.80
show_statsFunction · 0.70
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected