1
+ const ColKey = Union{Symbol,AbstractString}
2
+
1
3
"""
2
4
coerce(A, specs...; tight=false, verbosity=1)
3
5
@@ -16,7 +18,9 @@ both the `OldScitype` and `Union{Missing,OldScitype}` cases):
16
18
17
19
(iii) a dictionary of scientific types keyed on column names:
18
20
19
- coerce(X, d::AbstractDict{Symbol, <:Type}; verbosity=1)
21
+ coerce(X, d::AbstractDict{<:ColKey, <:Type}; verbosity=1)
22
+
23
+ where `ColKey = Union{Symbol,AbstractString}`.
20
24
21
25
### Examples
22
26
@@ -50,7 +54,7 @@ coerce(::Val{:other}, X, a...; kw...) =
50
54
51
55
_bad_dictionary () = throw (ArgumentError (
52
56
" A dictionary specifying a scitype conversion " *
53
- " must have type `AbstractDict{Symbol , <:Type}`. It's keys must " *
57
+ " must have type `AbstractDict{<:ColKey , <:Type}`. It's keys must " *
54
58
" be column names and its values be scientific types. " *
55
59
" E.g., `Dict(:cats=>Continuous, :dogs=>Textual`. " ))
56
60
coerce (:: Val{:table} , X, types_dict:: AbstractDict ; kw... ) =
@@ -68,7 +72,7 @@ coerce(::Val{:table}, X, specs...; kw...) = _bad_specs()
68
72
69
73
function coerce (:: Val{:table} ,
70
74
X,
71
- types_dict:: AbstractDict{Symbol , <:Type} ;
75
+ types_dict:: AbstractDict{<:ColKey , <:Type} ;
72
76
kw... )
73
77
isempty (types_dict) && return X
74
78
names = schema (X). names
103
107
# symbol=>type and type=>type pairs can be specified in place of a
104
108
# dictionary:
105
109
106
- feature_scitype_pairs (p:: Pair{Symbol ,<:Type} , X) = [p , ]
110
+ feature_scitype_pairs (p:: Pair{<:ColKey ,<:Type} , X) = [Symbol ( first (p)) => last (p) , ]
107
111
function feature_scitype_pairs (p:: Pair{<:Type,<:Type} , X)
108
112
from_scitype = first (p)
109
113
to_scitype = last (p)
@@ -121,7 +125,7 @@ for c in (:coerce, :coerce!)
121
125
ex = quote
122
126
function $c (:: Val{:table} ,
123
127
X,
124
- mixed_pairs:: Pair{<:Union{Symbol ,<:Type},<:Type} ...;
128
+ mixed_pairs:: Pair{<:Union{<:ColKey ,<:Type},<:Type} ...;
125
129
kw... )
126
130
components = map (p -> feature_scitype_pairs (p, X), mixed_pairs)
127
131
pairs = vcat (components... )
@@ -170,7 +174,7 @@ coerce!(::Val{:table}, X, specs...; kw...) = _bad_specs()
170
174
171
175
function coerce! (:: Val{:table} ,
172
176
X,
173
- types_dict:: AbstractDict{Symbol , <:Type} ;
177
+ types_dict:: AbstractDict{<:ColKey , <:Type} ;
174
178
kw... )
175
179
# DataFrame --> coerce_df!
176
180
if is_type (X, :DataFrames , :DataFrame )
189
193
190
194
In place coercion for a dataframe.(Unexported method)
191
195
"""
192
- function coerce_df! (df, tdict:: AbstractDict{Symbol , <:Type} ; kw... )
196
+ function coerce_df! (df, tdict:: AbstractDict{<:ColKey , <:Type} ; kw... )
193
197
names = schema (df). names
194
198
for name in names
195
199
name in keys (tdict) || continue
0 commit comments