Skip to content

Commit

Permalink
Merge pull request #32 from eliascarv/colspec-docstring
Browse files Browse the repository at this point in the history
Add docstring for ColSpec
  • Loading branch information
juliohm committed Apr 3, 2022
2 parents 1387167 + ac7c745 commit 3c8e494
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/transforms/colspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,40 @@
# types used to select a column
const ColSelector = Union{Symbol,Integer,AbstractString}

# union of types used to filter columns
"""
ColSpec
`ColSpec` is a union of types used to filter columns.
The `ColSpec` type together with the `ColSelector` union type and
the `_filter` internal function form the ColSpec interface.
To implement the ColSpec interface, the following steps must be performed:
1. add colspec fied:
```julia
struct MyTransform{S<:ColSpec,#= other type params =#}
colspec::S
# other fileds
end
```
2. use `_filter(colspec, cols)` internal function in apply:
```julia
function apply(transform::MyTransform, table)
allcols = Tables.columnnames(table)
# selected columns
cols = _filter(transform.colspec, allcols)
# code...
end
```
If you need to create constructors that accept
individual column selectors use the `ColSelector` type. Example:
```julia
function MyTransform(args::T...) where {T<:ColSelector}
# code...
end
```
"""
const ColSpec = Union{Vector{T},NTuple{N,T},Regex,Colon} where {N,T<:ColSelector}

# filter table columns using colspec
Expand Down

0 comments on commit 3c8e494

Please sign in to comment.