Skip to content

Commit

Permalink
docs(selectors): render the module instead of hand-picking the docume…
Browse files Browse the repository at this point in the history
…nted components
  • Loading branch information
cpcloud committed Feb 26, 2025
1 parent 421972a commit 358360c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
24 changes: 3 additions & 21 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -573,30 +573,12 @@ quartodoc:
- udf
- window
- kind: page
path: selectors
package: ibis
summary:
name: Column selectors
desc: Choose Table columns based on dtype, regex, and other criteria
path: selectors
package: ibis.selectors
contents:
- where
- numeric
- of_type
- startswith
- endswith
- contains
- matches
- any_of
- all_of
- cols
- across
- if_any
- if_all
- index
- first
- last
- all
- none
- selectors

- title: Type System
desc: "Data types and schemas"
Expand Down
43 changes: 9 additions & 34 deletions ibis/selectors.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Convenient column selectors.
Column selectors ("selectors") are convenience functions for selecting columns
that satisfy a particular condition. For example, selecting all string-typed
columns.
::: {.callout-tip}
## Check out the [blog post on selectors](../posts/selectors) for examples!
## Check out the [blog post on selectors](../posts/selectors) for more examples!
:::
## Rationale
Column selectors are convenience functions for selecting columns that share some property.
## Discussion
For example, a common task is to be able to select all numeric columns for a
subsequent computation.
Examples
--------
A common task is to be able to select all numeric columns for a subsequent
computation.
Without selectors this becomes quite verbose and tedious to write:
Expand Down Expand Up @@ -72,20 +72,6 @@
from ibis.common.typing import VarTuple # noqa: TC001


def __getattr__(name):
if name == "c":
util.warn_deprecated(
"c", instead="use `ibis.selectors.cols` instead", as_of="9.5"
)
return cols
elif name == "r":
util.warn_deprecated(
"r", instead="use `ibis.selectors.index` instead", as_of="9.5"
)
return index
raise AttributeError(name)


class Where(Selector):
predicate: Callable[[ir.Value], bool]

Expand Down Expand Up @@ -113,7 +99,6 @@ def where(predicate: Callable[[ir.Value], bool]) -> Selector:
>>> expr = t.select(s.where(lambda col: col.get_name() == "a"))
>>> expr.columns
('a',)
"""
return Where(predicate)

Expand All @@ -136,7 +121,6 @@ def numeric() -> Selector:
See Also
--------
[`of_type`](#ibis.selectors.of_type)
"""
return of_type(dt.Numeric)

Expand Down Expand Up @@ -190,7 +174,6 @@ def of_type(dtype: dt.DataType | str | type[dt.DataType]) -> Selector:
See Also
--------
[`numeric`](#ibis.selectors.numeric)
"""
if isinstance(dtype, str):
# A mapping of abstract or parametric types, to allow selecting all
Expand Down Expand Up @@ -252,7 +235,6 @@ def startswith(prefixes: str | tuple[str, ...]) -> Selector:
See Also
--------
[`endswith`](#ibis.selectors.endswith)
"""
return StartsWith(prefixes)

Expand Down Expand Up @@ -286,7 +268,6 @@ def endswith(suffixes: str | tuple[str, ...]) -> Selector:
See Also
--------
[`startswith`](#ibis.selectors.startswith)
"""
return EndsWith(suffixes)

Expand Down Expand Up @@ -340,7 +321,6 @@ def contains(
See Also
--------
[`matches`](#ibis.selectors.matches)
"""
return Contains(tuple(util.promote_list(needles)), how=how)

Expand Down Expand Up @@ -373,7 +353,6 @@ def matches(regex: str | re.Pattern) -> Selector:
See Also
--------
[`contains`](#ibis.selectors.contains)
"""
return Matches(re.compile(regex))

Expand Down Expand Up @@ -538,7 +517,6 @@ def across(
│ 42.0 │ 20.2 │ -1.92193 │ … │
│ … │ … │ … │ … │
└────────────────┴───────────────┴─────────────────────────┴───┘
"""
if names is None:
names = lambda col, fn: "_".join(filter(None, (col, fn)))
Expand Down Expand Up @@ -653,14 +631,11 @@ def if_all(selector: Selector, predicate: Deferred | Callable) -> IfAnyAll:
│ Gentoo │ Biscoe │ 1.241499 │ -1.089314 │ 1.570562 │ … │
│ Gentoo │ Biscoe │ 1.351398 │ -1.494420 │ 1.214987 │ … │
└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴───┘
"""
return IfAnyAll(selector=selector, predicate=predicate, summarizer=operator.and_)


class Slice(Concrete):
"""Hashable and smaller-scoped slice object versus the builtin one."""

start: int | str | None = None
stop: int | str | None = None
step: int | None = None
Expand Down

0 comments on commit 358360c

Please sign in to comment.