Skip to content

Commit

Permalink
Fix handling of variable_eltype in stack (#3043)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed May 2, 2022
1 parent 093d9fc commit 75f4dae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataFrames"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.3.3"
version = "1.3.4"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down Expand Up @@ -29,7 +29,7 @@ DataAPI = "1.9"
InvertedIndices = "1"
IteratorInterfaceExtensions = "0.1.1, 1"
Missings = "0.4.2, 1"
PooledArrays = "1.3.0"
PooledArrays = "1.4.2"
PrettyTables = "0.12, 1"
Reexport = "0.1, 0.2, 1"
ShiftedArrays = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/abstractdataframe/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function stack(df::AbstractDataFrame,
# (note that copyto! inserts levels in their order of appearance)
nms = names(df, ints_measure_vars)
simnms = similar(nms, variable_eltype)
catnms = simnms isa Vector ? PooledArray(catnms) : simnms
catnms = simnms isa Vector ? PooledArray(simnms) : simnms
copyto!(catnms, nms)
end
return DataFrame(AbstractVector[[repeat(df[!, c], outer=N) for c in ints_id_vars]..., # id_var columns
Expand Down
14 changes: 14 additions & 0 deletions test/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,18 @@ end
@test dfu.a isa Vector{Any}
end

@testset "variable_eltype in stack tests" begin
df = DataFrame(A=1:3, B=[2.0, -1.1, 2.8], C=["p", "q", "r"])
@test_throws MethodError stack(df, :C, variable_name=:D, variable_eltype=Int)
for T in (AbstractString, Any)
sdf = stack(df, [:A, :B], variable_name=:D, variable_eltype=T)
@test sdf == DataFrame(C=["p", "q", "r", "p", "q", "r"],
D=["A", "A", "A", "B", "B", "B"],
value=[1.0, 2.0, 3.0, 2.0, -1.1, 2.8])
@test sdf.C isa Vector{String}
@test sdf.value isa Vector{Float64}
@test sdf.D isa PooledVector{T}
end
end

end # module

2 comments on commit 75f4dae

@bkamins
Copy link
Member Author

@bkamins bkamins commented on 75f4dae May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register branch=patch_v1.3

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/59542

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.4 -m "<description of version>" 75f4dae361cfe9af783e934fbd52c6e5111d277c
git push origin v1.3.4

Please sign in to comment.