Skip to content

Commit

Permalink
docs: add more examples to Table.select()
Browse files Browse the repository at this point in the history
This is to make these other APIs more discoverable.
  • Loading branch information
NickCrews authored and cpcloud committed Oct 4, 2023
1 parent 9e45194 commit 735bbd0
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import pandas as pd
import pyarrow as pa

import ibis.selectors as s
import ibis.expr.types as ir
import ibis.selectors as s
from ibis.common.typing import SupportsSchema
from ibis.selectors import IfAnyAll, Selector
from ibis.expr.types.groupby import GroupedTable
from ibis.selectors import IfAnyAll, Selector

_ALIASES = (f"_ibis_view_{n:d}" for n in itertools.count())

Expand Down Expand Up @@ -1651,6 +1651,21 @@ def select(
│ Torgersen │ 36.7 │
└───────────┴────────────────┘
In that simple case, you could also just use python's indexing syntax
>>> t[["island", "bill_length_mm"]].head()
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ island ┃ bill_length_mm ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ string │ float64 │
├───────────┼────────────────┤
│ Torgersen │ 39.1 │
│ Torgersen │ 39.5 │
│ Torgersen │ 40.3 │
│ Torgersen │ nan │
│ Torgersen │ 36.7 │
└───────────┴────────────────┘
Projection by zero-indexed column position
>>> t.select(0, 4).head()
Expand Down Expand Up @@ -1681,6 +1696,23 @@ def select(
│ 2008 │
└───────────┘
You can do the same thing with a named expression, and using the
deferred API
>>> from ibis import _
>>> t.select((_.year + 1).name("next_year")).head()
┏━━━━━━━━━━━┓
┃ next_year ┃
┡━━━━━━━━━━━┩
│ int64 │
├───────────┤
│ 2008 │
│ 2008 │
│ 2008 │
│ 2008 │
│ 2008 │
└───────────┘
Projection with aggregation expressions
>>> t.select("island", bill_mean=t.bill_length_mm.mean()).head()
Expand Down Expand Up @@ -3688,8 +3720,9 @@ def pivot_wider(
└───────┴──────────┴──────────┴──────────┘
"""
import pandas as pd
import ibis.selectors as s

import ibis.expr.analysis as an
import ibis.selectors as s
from ibis import _

orig_names_from = util.promote_list(names_from)
Expand Down

0 comments on commit 735bbd0

Please sign in to comment.