Skip to content

Commit 1ac911a

Browse files
authored
Merge pull request #168 from JuliaAI/dev
For a 2.3.1 release
2 parents 664d5b4 + 4c4ed62 commit 1ac911a

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ScientificTypes"
22
uuid = "321657f4-b219-11e9-178b-2701a2544e81"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "2.3"
4+
version = "2.3.1"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"

src/coerce.jl

+4-11
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ DataFrame! does). An error is thrown otherwise. The arguments are the same as
162162
`coerce`.
163163
164164
"""
165-
coerce!(X, a...; kw...) = coerce!(Val(ST.trait(X)), X, a...; kw...)
165+
coerce!(X, a...; kw...) = begin
166+
coerce!(Val(ST.trait(X)), X, a...; kw...)
167+
end
166168

167169
coerce!(::Val{:other}, X, a...; kw...) =
168170
throw(CoercionError("`coerce!` is undefined for non-tabular data."))
@@ -198,16 +200,7 @@ function coerce_df!(df, tdict::AbstractDict{<:ColKey, <:Type}; kw...)
198200
for name in names
199201
name in keys(tdict) || continue
200202
coerce_type = tdict[name]
201-
# for DataFrames >= 0.19 df[!, name] = coerce(df[!, name], types(name))
202-
# but we want something that works more robustly... even for older
203-
# DataFrames; the only way to do this is to use the
204-
# `df.name = something` but we cannot use setindex! without throwing
205-
# a deprecation warning... metaprogramming to the rescue.
206-
name_str = "$name"
207-
ex = quote
208-
$df.$name = coerce($df.$name, $coerce_type, $kw...)
209-
end
210-
eval(ex)
203+
df[!, name] = coerce(df[!, name], coerce_type; kw...)
211204
end
212205
return df
213206
end

test/extra_coercion.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
@testset "issue #7" begin
2-
df = DataFrame(x=[1,2,3,4], y=["a","b","c","a"])
1+
@testset "coerce!" begin
2+
df = DataFrame(x=[1,2,3,4],
3+
y=["a","b","c","a"],
4+
z = Union{Missing,Int}[10, 20, 30, 40])
35
coerce!(df, Textual=>Finite)
4-
@test scitype(df) == Table{Union{ AbstractArray{Count,1},
5-
AbstractArray{Multiclass{3},1} }}
6+
coerce!(df, Union{Missing,Count}=>Count, tight=true) # issue #166
7+
@test scitype(df) == Table{Union{AbstractArray{Count,1},
8+
AbstractArray{Multiclass{3},1} }}
69
end
710

811
# issue #9

0 commit comments

Comments
 (0)