@@ -2123,6 +2123,25 @@ def count(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
2123
2123
-------
2124
2124
IntegerScalar
2125
2125
Number of elements in an expression
2126
+
2127
+ Examples
2128
+ --------
2129
+ >>> import ibis
2130
+ >>> ibis.options.interactive = True
2131
+ >>> t = ibis.memtable(
2132
+ ... {
2133
+ ... "id": [1, 2, 3, 4, 5, 6],
2134
+ ... "color": ["Red", "Green", "Blue", "Blue", "Red", "Blue"],
2135
+ ... }
2136
+ ... )
2137
+ >>> t.count()
2138
+ ┌───┐
2139
+ │ 6 │
2140
+ └───┘
2141
+ >>> t.count(where=t.color == "Blue")
2142
+ ┌───┐
2143
+ │ 3 │
2144
+ └───┘
2126
2145
"""
2127
2146
return ops .Count (self , where = self ._bind_to_parent_table (where )).to_expr ()
2128
2147
@@ -2352,11 +2371,51 @@ def dense_rank(self) -> ir.IntegerColumn:
2352
2371
return ibis .dense_rank ().over (order_by = self )
2353
2372
2354
2373
def percent_rank (self ) -> Column :
2355
- """Return the relative rank of the values in the column."""
2374
+ """Return the relative rank of the values in the column.
2375
+
2376
+ Examples
2377
+ --------
2378
+ >>> import ibis
2379
+ >>> ibis.options.interactive = True
2380
+ >>> t = ibis.memtable({"values": [1, 2, 1, 2, 3, 2]})
2381
+ >>> t.mutate(percent_rank=t.values.percent_rank())
2382
+ ┏━━━━━━━━┳━━━━━━━━━━━━━━┓
2383
+ ┃ values ┃ percent_rank ┃
2384
+ ┡━━━━━━━━╇━━━━━━━━━━━━━━┩
2385
+ │ int64 │ float64 │
2386
+ ├────────┼──────────────┤
2387
+ │ 1 │ 0.0 │
2388
+ │ 1 │ 0.0 │
2389
+ │ 2 │ 0.4 │
2390
+ │ 2 │ 0.4 │
2391
+ │ 2 │ 0.4 │
2392
+ │ 3 │ 1.0 │
2393
+ └────────┴──────────────┘
2394
+ """
2356
2395
return ibis .percent_rank ().over (order_by = self )
2357
2396
2358
2397
def cume_dist (self ) -> Column :
2359
- """Return the cumulative distribution over a window."""
2398
+ """Return the cumulative distribution over a window.
2399
+
2400
+ Examples
2401
+ --------
2402
+ >>> import ibis
2403
+ >>> ibis.options.interactive = True
2404
+ >>> t = ibis.memtable({"values": [1, 2, 1, 2, 3, 2]})
2405
+ >>> t.mutate(cume_dist=t.values.cume_dist())
2406
+ ┏━━━━━━━━┳━━━━━━━━━━━┓
2407
+ ┃ values ┃ cume_dist ┃
2408
+ ┡━━━━━━━━╇━━━━━━━━━━━┩
2409
+ │ int64 │ float64 │
2410
+ ├────────┼───────────┤
2411
+ │ 1 │ 0.333333 │
2412
+ │ 1 │ 0.333333 │
2413
+ │ 2 │ 0.833333 │
2414
+ │ 2 │ 0.833333 │
2415
+ │ 2 │ 0.833333 │
2416
+ │ 3 │ 1.000000 │
2417
+ └────────┴───────────┘
2418
+ """
2360
2419
return ibis .cume_dist ().over (order_by = self )
2361
2420
2362
2421
def ntile (self , buckets : int | ir .IntegerValue ) -> ir .IntegerColumn :
@@ -2366,6 +2425,25 @@ def ntile(self, buckets: int | ir.IntegerValue) -> ir.IntegerColumn:
2366
2425
----------
2367
2426
buckets
2368
2427
Number of buckets to partition into
2428
+
2429
+ Examples
2430
+ --------
2431
+ >>> import ibis
2432
+ >>> ibis.options.interactive = True
2433
+ >>> t = ibis.memtable({"values": [1, 2, 1, 2, 3, 2]})
2434
+ >>> t.mutate(ntile=t.values.ntile(3))
2435
+ ┏━━━━━━━━┳━━━━━━━┓
2436
+ ┃ values ┃ ntile ┃
2437
+ ┡━━━━━━━━╇━━━━━━━┩
2438
+ │ int64 │ int64 │
2439
+ ├────────┼───────┤
2440
+ │ 1 │ 0 │
2441
+ │ 1 │ 0 │
2442
+ │ 2 │ 1 │
2443
+ │ 2 │ 1 │
2444
+ │ 2 │ 2 │
2445
+ │ 3 │ 2 │
2446
+ └────────┴───────┘
2369
2447
"""
2370
2448
return ibis .ntile (buckets ).over (order_by = self )
2371
2449
0 commit comments