Skip to content

Commit 7cc5282

Browse files
committed
Add Polars code comparison showing explicit column approach
1 parent 4f33ea5 commit 7cc5282

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/ezmiller/relaunching_tablecloth_time.clj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,20 @@
4545
;; tree-based index is pure overhead — you'd rebuild it constantly. As Chris
4646
;; Nuernberger (author of tech.ml.dataset) put it: "Just sorting the dataset and
4747
;; using binary search will outperform most/all tree structures in this scenario."
48-
;; (Notably, [Polars](https://pola.rs/) — the Rust-based DataFrame library gaining
49-
;; traction as a Pandas alternative — reached the same conclusion and has no index
50-
;; by design.)
48+
;; Notably, [Polars](https://pola.rs/) — the Rust-based DataFrame library gaining
49+
;; traction as a Pandas alternative — reached the same conclusion. Polars has no
50+
;; index by design; you always specify the column explicitly:
51+
;;
52+
;; ```python
53+
;; # Pandas (implicit index)
54+
;; df = df.set_index('Time')
55+
;; df['2024-01'] # slice via index
56+
;; df.resample('D').mean() # resample via index
57+
;;
58+
;; # Polars (explicit column)
59+
;; df.filter(pl.col('Time').dt.year() == 2024, pl.col('Time').dt.month() == 1)
60+
;; df.group_by_dynamic('Time', every='1d').agg(pl.col('Demand').mean())
61+
;; ```
5162
;;
5263
;; **On convenience:** The index adds implicit state threaded through your data.
5364
;; Tablecloth's API avoids this — you always say which columns you're operating on.

0 commit comments

Comments
 (0)