Skip to content

Commit 03f0629

Browse files
authored
Improve docstring of AsTable (#2851)
1 parent 3a71ae5 commit 03f0629

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/other/utils.jl

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,56 @@
11
"""
22
AsTable(cols)
33
4-
A type used for selection operations to signal that the columns selected by the
5-
wrapped selector should be passed as a `NamedTuple` to the function.
4+
A type having a special meaning in `source => transformation => destination`
5+
selection operations supported by [`combine`](@ref), [`select`](@ref), [`select!`](@ref),
6+
[`transform`](@ref), [`transform!`](@ref), [`subset`](@ref), and [`subset!`](@ref).
7+
8+
If `AsTable(cols)` is used in `source` position it signals that the columns selected
9+
by the wrapped selector `cols` should be passed as a `NamedTuple` to the function.
10+
11+
If `AsTable` is used in `destination` position it means that the result of
12+
the `transformation` operation is a vector of containers
13+
(or a single container if `ByRow(transformation)` is used)
14+
that should be expanded into multiple columns using `keys` to get column names.
15+
16+
# Examples
17+
```jldoctest
18+
julia> df1 = DataFrame(a=1:3, b=11:13)
19+
3×2 DataFrame
20+
Row │ a b
21+
│ Int64 Int64
22+
─────┼──────────────
23+
1 │ 1 11
24+
2 │ 2 12
25+
3 │ 3 13
26+
27+
julia> df2 = select(df1, AsTable([:a, :b]) => ByRow(identity))
28+
3×1 DataFrame
29+
Row │ a_b_identity
30+
│ NamedTuple…
31+
─────┼─────────────────
32+
1 │ (a = 1, b = 11)
33+
2 │ (a = 2, b = 12)
34+
3 │ (a = 3, b = 13)
35+
36+
julia> select(df2, :a_b_identity => AsTable)
37+
3×2 DataFrame
38+
Row │ a b
39+
│ Int64 Int64
40+
─────┼──────────────
41+
1 │ 1 11
42+
2 │ 2 12
43+
3 │ 3 13
44+
45+
julia> select(df1, AsTable([:a, :b]) => ByRow(nt -> map(x -> x^2, nt)) => AsTable)
46+
3×2 DataFrame
47+
Row │ a b
48+
│ Int64 Int64
49+
─────┼──────────────
50+
1 │ 1 121
51+
2 │ 4 144
52+
3 │ 9 169
53+
```
654
"""
755
struct AsTable
856
cols

0 commit comments

Comments
 (0)