Skip to content

Commit 288ca61

Browse files
committed
docs(news): More details about dynamic dots
1 parent 55e1ae9 commit 288ca61

File tree

1 file changed

+85
-11
lines changed

1 file changed

+85
-11
lines changed

NEWS.md

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@ This is an update that corresponds to Python Polars 1.32.0, which includes signi
1717
- `<lazyframe>$unique()` and `<dataframe>$unique()`'s first argument is replaced from `subset` to `...`
1818
(dynamic dots) (#1463).
1919
Because of this change, it is also deprecated to pass the following objects as the first argument of these functions:
20+
2021
- `NULL`: Use `cs$all()` or pass nothing to select all columns.
21-
- A list of column names or selectors: Use `!!!` to expand the list. e.g. `!!!list("col1", "col2")`.
22+
If you want to pass column selections as a variable, you can use the `%||%` (base R >= 4.4.0, or `{rlang}`'s op-null-default)
23+
operator to replace `NULL` with `cs$all()`:
24+
25+
```r
26+
subset <- nullable_selection %||% cs$all()
27+
lf$unique(!!!c(subset))
28+
```
29+
30+
- A list of column names or selectors: Use `!!!` to expand the list to the dynamic-dots.
31+
32+
```r
33+
subset <- list("col1", "col2")
34+
lf$unique(!!!c(subset))
35+
```
2236

2337
### New features
2438

@@ -31,16 +45,76 @@ This is an update that corresponds to Python Polars 1.32.0, which includes signi
3145
- `cs$struct()` for Struct data types.
3246
- `cs$nested()` for List, Array, or Struct data types.
3347
- polars selectors can now be used in place of column names in more locations (#1452).
34-
- The `...` argument (dynamic dots) of `<dataframe>$to_dummies()`.
35-
- The `...` argument (dynamic dots) of `<dataframe>$partition_by()`.
36-
- The `...` argument (dynamic dots) of `<lazyframe>$drop()` and `<dataframe>$drop()`.
37-
- The `...` argument (dynamic dots) of `<lazyframe>$drop_nulls()` and `<dataframe>$drop_nulls()`.
38-
- The `...` argument (dynamic dots) of `<lazyframe>$drop_nans()` and `<dataframe>$drop_nans()`.
39-
- The `...` argument (dynamic dots) of `<lazyframe>$unnest()` and `<dataframe>$unnest()`.
40-
- The `...` argument (dynamic dots) of `<lazyframe>$explode()` and `<dataframe>$explode()`.
41-
- The `...` argument (dynamic dots) of `<lazyframe>$unique()` and `<dataframe>$unique()` (#1463).
42-
- The `on`, `index`, and `values` arguments of `<dataframe>$pivot()`.
43-
- The `on` and `index` arguments of `<lazyframe>$unpivot()` and `<dataframe>$unpivot()`.
48+
49+
- `...` (dynamic dots) of these functions.
50+
- `<dataframe>$to_dummies()`
51+
- `<dataframe>$partition_by()`
52+
- `<lazyframe>$drop_nulls()` and `<dataframe>$drop_nulls()`
53+
- `<lazyframe>$drop_nans()` and `<dataframe>$drop_nans()`
54+
- `<lazyframe>$unique()` and `<dataframe>$unique()`
55+
- `<lazyframe>$drop()` and `<dataframe>$drop()`
56+
- `<lazyframe>$explode()` and `<dataframe>$explode()`
57+
- `<lazyframe>$unnest()` and `<dataframe>$unnest()`
58+
- `<dataframe>$pivot()`'s `on`, `index`, and `values`.
59+
- `<lazyframe>$join()` and `<dataframe>$join()`'s `on` and `index`.
60+
61+
This change also fixes the odd behavior of some functions that had the semantics
62+
of selecting all columns by default
63+
(`$drop_nulls()`, `$drop_nans()`, and `$unique()` of lazyframe or dataframe).
64+
65+
In the previous version, passing `c()` (`NULL`) would result in a strange behavior
66+
doesn't match neither of "select nothing" or "select all columns".
67+
And, expanding an empty vector with `!!!` would select all columns.
68+
69+
```r
70+
### OLD
71+
df <- pl$DataFrame(a = c(NA, TRUE), b = 1:2)
72+
df$drop_nulls(c())
73+
#> shape: (0, 2)
74+
#> ┌──────┬─────┐
75+
#> │ a ┆ b │
76+
#> │ --- ┆ --- │
77+
#> │ bool ┆ i32 │
78+
#> ╞══════╪═════╡
79+
#> └──────┴─────┘
80+
81+
df$drop_nulls(!!!c())
82+
#> shape: (1, 2)
83+
#> ┌──────┬─────┐
84+
#> │ a ┆ b │
85+
#> │ --- ┆ --- │
86+
#> │ bool ┆ i32 │
87+
#> ╞══════╪═════╡
88+
#> │ true ┆ 2 │
89+
#> └──────┴─────┘
90+
```
91+
92+
In the new version, passing `c()` (`NULL`) will cause an error,
93+
and expanding an empty vector with `!!!` will select no columns.
94+
95+
```r
96+
### NEW
97+
df <- pl$DataFrame(a = c(NA, TRUE), b = 1:2)
98+
df$drop_nulls(c())
99+
#> Error:
100+
#> ! Evaluation failed in `$drop_nulls()`.
101+
#> Caused by error:
102+
#> ! Evaluation failed in `$drop_nulls()`.
103+
#> Caused by error:
104+
#> ! `...` can only contain single strings or polars selectors.
105+
106+
df$drop_nulls(!!!c())
107+
#> shape: (2, 2)
108+
#> ┌──────┬─────┐
109+
#> │ a ┆ b │
110+
#> │ --- ┆ --- │
111+
#> │ bool ┆ i32 │
112+
#> ╞══════╪═════╡
113+
#> │ null ┆ 1 │
114+
#> │ true ┆ 2 │
115+
#> └──────┴─────┘
116+
```
117+
44118
- `pl$nth()` gains the `strict` argument (#1452).
45119
- `<expr>$str$pad_end()` and `<expr>$str$pad_start()`'s `length` argument accepts a polars expression (#1452).
46120
- `<expr>$str$to_integer()` gains the `dtype` argument to specify the output data type (#1452).

0 commit comments

Comments
 (0)