Carries out a selection operation on a tables.Table object. Parameters ---------- table : a Table object where : list of Terms (or convertible to) start, stop: indices to start and/or stop selection
| 5481 | |
| 5482 | |
| 5483 | class Selection: |
| 5484 | """ |
| 5485 | Carries out a selection operation on a tables.Table object. |
| 5486 | |
| 5487 | Parameters |
| 5488 | ---------- |
| 5489 | table : a Table object |
| 5490 | where : list of Terms (or convertible to) |
| 5491 | start, stop: indices to start and/or stop selection |
| 5492 | |
| 5493 | """ |
| 5494 | |
| 5495 | def __init__( |
| 5496 | self, |
| 5497 | table: Table, |
| 5498 | where=None, |
| 5499 | start: int | None = None, |
| 5500 | stop: int | None = None, |
| 5501 | ) -> None: |
| 5502 | self.table = table |
| 5503 | self.where = where |
| 5504 | self.start = start |
| 5505 | self.stop = stop |
| 5506 | self.condition = None |
| 5507 | self.filter = None |
| 5508 | self.terms = None |
| 5509 | self.coordinates = None |
| 5510 | |
| 5511 | if is_list_like(where): |
| 5512 | # see if we have a passed coordinate like |
| 5513 | with suppress(ValueError): |
| 5514 | inferred = lib.infer_dtype(where, skipna=False) |
| 5515 | if inferred in ("integer", "boolean"): |
| 5516 | where = np.asarray(where) |
| 5517 | if where.dtype == np.bool_: |
| 5518 | start, stop = self.start, self.stop |
| 5519 | if start is None: |
| 5520 | start = 0 |
| 5521 | if stop is None: |
| 5522 | stop = self.table.nrows |
| 5523 | self.coordinates = np.arange(start, stop)[where] |
| 5524 | elif issubclass(where.dtype.type, np.integer): |
| 5525 | if (self.start is not None and (where < self.start).any()) or ( |
| 5526 | self.stop is not None and (where >= self.stop).any() |
| 5527 | ): |
| 5528 | raise ValueError( |
| 5529 | "where must have index locations >= start and < stop" |
| 5530 | ) |
| 5531 | self.coordinates = where |
| 5532 | |
| 5533 | if self.coordinates is None: |
| 5534 | self.terms = self.generate(where) |
| 5535 | |
| 5536 | # create the numexpr & the filter |
| 5537 | if self.terms is not None: |
| 5538 | self.condition, self.filter = self.terms.evaluate() |
| 5539 | |
| 5540 | @overload |
no outgoing calls
no test coverage detected