Skip to content

Commit 9f60ca3

Browse files
authored
docs(examples): add selector example for none (#10425)
## Description of changes Adds an example of using the `s.none()` selector based on discussion in #10421. This is the last column selector needing an example on the [docs page](https://ibis-project.org/reference/selectors).
1 parent 130e4d5 commit 9f60ca3

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

ibis/selectors.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,43 @@ def expand_names(self, table: ir.Table) -> frozenset[str]:
827827

828828
@public
829829
def none() -> Selector:
830-
"""Return no columns."""
830+
"""Return no columns.
831+
832+
Examples
833+
--------
834+
>>> import ibis
835+
>>> import ibis.selectors as s
836+
>>> ibis.options.interactive = True
837+
>>> t = ibis.memtable(
838+
... {
839+
... "id": [1, 2, 3, 4, 5, 6],
840+
... "color": ["Red", "Green", "Blue", "Blue", "Red", "Blue"],
841+
... }
842+
... )
843+
844+
`s.none()` results in an empty expansion.
845+
846+
>>> s.none().expand(t)
847+
[]
848+
849+
This can be useful when you want to pivot a table without identifying unique
850+
observations.
851+
852+
>>> t.pivot_wider(
853+
... id_cols=s.none(),
854+
... names_from="color",
855+
... values_from="color",
856+
... values_agg="count",
857+
... names_sort=True,
858+
... )
859+
┏━━━━━━━┳━━━━━━━┳━━━━━━━┓
860+
┃ Blue ┃ Green ┃ Red ┃
861+
┡━━━━━━━╇━━━━━━━╇━━━━━━━┩
862+
│ int64 │ int64 │ int64 │
863+
├───────┼───────┼───────┤
864+
│ 3 │ 1 │ 2 │
865+
└───────┴───────┴───────┘
866+
"""
831867
return NoColumns()
832868

833869

0 commit comments

Comments
 (0)