-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appending Dataframe
s after CSV.read
fails for different length String
columns
#3044
Comments
Dataframe
s after CSV.read
failsDataframe
s after CSV.read
fails for different length String
columns
This is not an error, but a correct behavior. @quinnj - there is probably nothing we can do automatically about it, right? The solution is the following:
|
Thanks for the reply. Your solution was also the solution I came to, but it might be difficult to resolve or understand for new users. |
Yes, I agree. That is why I pinged @quinnj who maintains InlineStrings.jl. |
@bkamins, what ends up getting called internally for |
by default we use Alternatively you can write:
to explicitly ask for promotion and in this case all things work as @jd-foster expects. |
I think I would personally expect |
I guess we currently have this behavior with julia> x = [1, 2, 3]
3-element Vector{Int64}:
1
2
3
julia> y = [1.2, 3.4, 5.6]
3-element Vector{Float64}:
1.2
3.4
5.6
julia> append!(x, y)
ERROR: InexactError: Int64(1.2)
Stacktrace:
[1] Int64
@ ./float.jl:788 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] setindex!
@ ./array.jl:966 [inlined]
[4] _unsafe_copyto!(dest::Vector{Int64}, doffs::Int64, src::Vector{Float64}, soffs::Int64, n::Int64)
@ Base ./array.jl:253
[5] unsafe_copyto!
@ ./array.jl:307 [inlined]
[6] _copyto_impl!
@ ./array.jl:331 [inlined]
[7] copyto!
@ ./array.jl:317 [inlined]
[8] append!(a::Vector{Int64}, items::Vector{Float64})
@ Base ./array.jl:1109
[9] top-level scope
@ REPL[3]:1
julia> append!(y, x)
9-element Vector{Float64}:
1.2
3.4
5.6
1.0
2.0
3.0
0.0
0.0
0.0
i.e. we'll promote the incoming vector to the original vector type, but won't modify the original vector type to promote to a common type. |
This is exactly why |
An error arises when using
CSV.read(filename,DataFrames)
on two or more files withString
columns, then callingappend!
.Maybe not an issue with DataFrames.jl per se, but if one file has a column parsed as
String15
and the second has longer strings in the same column parsed asString31
, then the appending of the vectors fails due to an inability to "promote" to the longer type.See also:
JuliaData/CSV.jl#945
MWE:
I get:
The text was updated successfully, but these errors were encountered: