Skip to content

Commit 169ea82

Browse files
committed
docsting for filter/!
1 parent 0107290 commit 169ea82

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

src/dataset/other.jl

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,9 +1058,73 @@ n(x) = count(!ismissing, x)
10581058
"""
10591059
filter(ds, cols; [type = all,...])
10601060
1061-
A convenient shortcut for ds[byrow(ds, type, cols; ...), :]. `type` can be any function supported by `byrow` which returns a Vector{Bool} or BitVector.
1061+
A convenient shortcut for `ds[byrow(ds, type, cols; ...), :]`.
10621062
1063-
See [`byrow`](@ref)
1063+
`type` can be any function supported by `byrow` which returns a Vector{Bool} or BitVector.
1064+
1065+
See [`byrow`](@ref), [`filter!`](@ref)
1066+
1067+
# Examples
1068+
1069+
```jldoctest
1070+
julia> ds = Dataset(x = [1,2,3,4,5], y = [1.5,2.3,-1,0,2.0], z = Bool[1,0,1,0,1])
1071+
5×3 Dataset
1072+
Row │ x y z
1073+
│ identity identity identity
1074+
│ Int64? Float64? Bool?
1075+
─────┼──────────────────────────────
1076+
1 │ 1 1.5 true
1077+
2 │ 2 2.3 false
1078+
3 │ 3 -1.0 true
1079+
4 │ 4 0.0 false
1080+
5 │ 5 2.0 true
1081+
1082+
julia> filter(ds, :z)
1083+
3×3 Dataset
1084+
Row │ x y z
1085+
│ identity identity identity
1086+
│ Int64? Float64? Bool?
1087+
─────┼──────────────────────────────
1088+
1 │ 1 1.5 true
1089+
2 │ 3 -1.0 true
1090+
3 │ 5 2.0 true
1091+
1092+
julia> filter(ds, 1:2, by = [iseven, >(2.0)])
1093+
1×3 Dataset
1094+
Row │ x y z
1095+
│ identity identity identity
1096+
│ Int64? Float64? Bool?
1097+
─────┼──────────────────────────────
1098+
1 │ 2 2.3 false
1099+
1100+
julia> filter(ds, 1:2, type = any, by = [iseven, >(2.0)])
1101+
2×3 Dataset
1102+
Row │ x y z
1103+
│ identity identity identity
1104+
│ Int64? Float64? Bool?
1105+
─────┼──────────────────────────────
1106+
1 │ 2 2.3 false
1107+
2 │ 4 0.0 false
1108+
1109+
julia> filter(ds, 1:3, type = issorted, rev = true)
1110+
2×3 Dataset
1111+
Row │ x y z
1112+
│ identity identity identity
1113+
│ Int64? Float64? Bool?
1114+
─────┼──────────────────────────────
1115+
1 │ 4 0.0 false
1116+
2 │ 5 2.0 true
1117+
1118+
julia> filter(ds, 2:3, type = isless, with = :x)
1119+
3×3 Dataset
1120+
Row │ x y z
1121+
│ identity identity identity
1122+
│ Int64? Float64? Bool?
1123+
─────┼──────────────────────────────
1124+
1 │ 3 -1.0 true
1125+
2 │ 4 0.0 false
1126+
3 │ 5 2.0 true
1127+
```
10641128
"""
10651129
function Base.filter(ds::AbstractDataset, cols::Union{ColumnIndex, MultiColumnIndex}; view = false, type= all, kwargs...)
10661130
if view
@@ -1072,9 +1136,15 @@ end
10721136
"""
10731137
filter!(ds, cols; [type = all, ...])
10741138
1075-
A convenient shortcut for deleteat![ds, .!byrow(ds, type, cols; ...)). `type` can be any function supported by `byrow` which returns a Vector{Bool} or BitVector.
1139+
Variant of `filter` which replaces the passed data set with the filtered one.
1140+
1141+
It is a convenient shortcut for `deleteat![ds, .!byrow(ds, type, cols; ...)]`.
1142+
1143+
`type` can be any function supported by `byrow` which returns a Vector{Bool} or BitVector.
1144+
1145+
Refer to [`filter`](@ref) for exmaples.
10761146
1077-
See [`byrow`](@ref)
1147+
See [`byrow`](@ref), [`filter`](@ref)
10781148
"""
10791149
Base.filter!(ds::Dataset, cols::Union{ColumnIndex, MultiColumnIndex}; type = all, kwargs...) = deleteat!(ds, .!byrow(ds, type, cols; kwargs...))
10801150

0 commit comments

Comments
 (0)