Skip to content

Commit 41c8f23

Browse files
authored
docs(examples): add Value.asc and Value.desc examples (#10515)
## Description of changes Sets up examples, parameter, return information, and links to respective top level equivalent functions for [Value.asc](https://ibis-project.org/reference/expression-generic#ibis.expr.types.generic.Value.asc) and [Value.desc](https://ibis-project.org/reference/expression-generic#ibis.expr.types.generic.Value.desc). Fixes small typo with weather -> whether.
1 parent 7595ca6 commit 41c8f23

File tree

2 files changed

+90
-4
lines changed

2 files changed

+90
-4
lines changed

ibis/expr/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def desc(expr: ir.Column | str, nulls_first: bool = False) -> ir.Value:
591591
expr
592592
The expression or column name to use for sorting
593593
nulls_first
594-
Bool to indicate weather to put NULL values first or not.
594+
Bool to indicate whether to put NULL values first or not.
595595
596596
See Also
597597
--------
@@ -632,7 +632,7 @@ def asc(expr: ir.Column | str, nulls_first: bool = False) -> ir.Value:
632632
expr
633633
The expression or column name to use for sorting
634634
nulls_first
635-
Bool to indicate weather to put NULL values first or not.
635+
Bool to indicate whether to put NULL values first or not.
636636
637637
See Also
638638
--------

ibis/expr/types/generic.py

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,11 +1192,97 @@ def __lt__(self, other: Value) -> ir.BooleanValue:
11921192
return _binop(ops.Less, self, other)
11931193

11941194
def asc(self, nulls_first: bool = False) -> ir.Value:
1195-
"""Sort an expression ascending."""
1195+
"""Sort an expression ascending.
1196+
1197+
Parameters
1198+
----------
1199+
nulls_first
1200+
Whether to sort `NULL` values first
1201+
1202+
Returns
1203+
-------
1204+
Value
1205+
Sorted expression
1206+
1207+
See Also
1208+
--------
1209+
[`ibis.asc()`](./expression-generic.qmd#ibis.asc)
1210+
1211+
Examples
1212+
--------
1213+
>>> import ibis
1214+
>>> ibis.options.interactive = True
1215+
>>> t = ibis.memtable({"a": [1, 2, 3, None]})
1216+
>>> t.order_by(t.a.asc())
1217+
┏━━━━━━━━━┓
1218+
┃ a ┃
1219+
┡━━━━━━━━━┩
1220+
│ float64 │
1221+
├─────────┤
1222+
│ 1.0 │
1223+
│ 2.0 │
1224+
│ 3.0 │
1225+
│ NULL │
1226+
└─────────┘
1227+
>>> t.order_by(t.a.asc(nulls_first=True))
1228+
┏━━━━━━━━━┓
1229+
┃ a ┃
1230+
┡━━━━━━━━━┩
1231+
│ float64 │
1232+
├─────────┤
1233+
│ NULL │
1234+
│ 1.0 │
1235+
│ 2.0 │
1236+
│ 3.0 │
1237+
└─────────┘
1238+
"""
11961239
return ops.SortKey(self, ascending=True, nulls_first=nulls_first).to_expr()
11971240

11981241
def desc(self, nulls_first: bool = False) -> ir.Value:
1199-
"""Sort an expression descending."""
1242+
"""Sort an expression descending.
1243+
1244+
Parameters
1245+
----------
1246+
nulls_first
1247+
Whether to sort `NULL` values first.
1248+
1249+
Returns
1250+
-------
1251+
Value
1252+
Sorted expression
1253+
1254+
See Also
1255+
--------
1256+
[`ibis.desc()`](./expression-generic.qmd#ibis.desc)
1257+
1258+
Examples
1259+
--------
1260+
>>> import ibis
1261+
>>> ibis.options.interactive = True
1262+
>>> t = ibis.memtable({"a": [1, 2, 3, None]})
1263+
>>> t.order_by(t.a.desc())
1264+
┏━━━━━━━━━┓
1265+
┃ a ┃
1266+
┡━━━━━━━━━┩
1267+
│ float64 │
1268+
├─────────┤
1269+
│ 3.0 │
1270+
│ 2.0 │
1271+
│ 1.0 │
1272+
│ NULL │
1273+
└─────────┘
1274+
>>> t.order_by(t.a.desc(nulls_first=True))
1275+
┏━━━━━━━━━┓
1276+
┃ a ┃
1277+
┡━━━━━━━━━┩
1278+
│ float64 │
1279+
├─────────┤
1280+
│ NULL │
1281+
│ 3.0 │
1282+
│ 2.0 │
1283+
│ 1.0 │
1284+
└─────────┘
1285+
"""
12001286
return ops.SortKey(self, ascending=False, nulls_first=nulls_first).to_expr()
12011287

12021288
def to_pandas(self, **kwargs) -> pd.Series:

0 commit comments

Comments
 (0)