7
7
8
8
Return a copy of the table, ensuring that the scientific types of the columns match the new specification.
9
9
10
+ Coerce(S)
11
+
12
+ Coerce all columns of the table with scientific type `S`.
13
+
10
14
This transform uses the `DataScienceTraits.coerce` function. Please see their docstring for more details.
11
15
12
16
# Examples
@@ -18,23 +22,28 @@ Coerce(:a => DST.Continuous, :b => DST.Continuous)
18
22
Coerce("a" => DST.Continuous, "b" => DST.Continuous)
19
23
```
20
24
"""
21
- struct Coerce{S<: ColumnSelector } <: StatelessFeatureTransform
25
+ struct Coerce{S<: ColumnSelector ,T } <: StatelessFeatureTransform
22
26
selector:: S
23
- scitypes:: Vector{DataType}
27
+ scitypes:: T
24
28
end
25
29
26
30
Coerce () = throw (ArgumentError (" cannot create Coerce transform without arguments" ))
27
31
32
+ Coerce (scitype:: Type{<:SciType} ) = Coerce (AllSelector (), scitype)
33
+
28
34
Coerce (pairs:: Pair{C,DataType} ...) where {C<: Column } = Coerce (selector (first .(pairs)), collect (last .(pairs)))
29
35
30
36
isrevertible (:: Type{<:Coerce} ) = true
31
37
38
+ _typedict (scitype:: Type{<:SciType} , snames) = Dict (nm => scitype for nm in snames)
39
+ _typedict (scitypes:: AbstractVector , snames) = Dict (zip (snames, scitypes))
40
+
32
41
function applyfeat (transform:: Coerce , feat, prep)
33
42
cols = Tables. columns (feat)
34
43
names = Tables. columnnames (cols)
35
44
types = Tables. schema (feat). types
36
45
snames = transform. selector (names)
37
- typedict = Dict ( zip (snames, transform. scitypes) )
46
+ typedict = _typedict ( transform. scitypes, snames )
38
47
39
48
columns = map (names) do name
40
49
x = Tables. getcolumn (cols, name)
0 commit comments