Skip to content

Commit

Permalink
missing makeunique + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kescobo committed Oct 12, 2020
1 parent 2f3e7b0 commit 040d856
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/abstractdataframe/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ with name specified by `dest_namescol`.
with `_i` (`i` starting at 1 for the first duplicate).
Note: The element types of columns in resulting `DataFrame`
(other than the first column, which always has element type `String`)
(other than the first column, w hich always has element type `String`)
will depend on the element types of _all_ input columns
based on the result of `promote_type`.
That is, if the source data frame contains `Int` and `Float64` columns,
Expand Down Expand Up @@ -485,12 +485,12 @@ function Base.permutedims(df::AbstractDataFrame, src_namescol::ColumnIndex,
df_permuted = DataFrame(dest_namescol => names(df_notsrc))

if ncol(df_notsrc) == 0
df_tmp = DataFrame((n=>[] for n in df[!, src_namescol])...)
df_tmp = DataFrame((n=>[] for n in df[!, src_namescol])..., makeunique=makeunique)
else
m = permutedims(Matrix(df_notsrc))
df_tmp = rename!(DataFrame(Tables.table(m)), df[!, src_namescol], makeunique=makeunique)
end
return hcat!(df_permuted, df_tmp, copycols=false)
return hcat!(df_permuted, df_tmp, makeunique=makeunique, copycols=false)
end

function Base.permutedims(df::AbstractDataFrame, src_namescol::ColumnIndex=1;
Expand Down
5 changes: 4 additions & 1 deletion test/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,11 @@ end

df3 = DataFrame(a=fill("x", 10), b=rand(10), c=rand(Int, 10), d=rand(Bool, 10))

d3pd_names = ["a", "x", ("x_$i" for i in 1:9)...]
@test_throws ArgumentError permutedims(df3)
@test names(permutedims(df3, makeunique=true)) == ["a", "x", ("x_$i" for i in 1:9)...]
@test names(permutedims(df3, makeunique=true)) == d3pd_names
@test_throws ArgumentError permutedims(df3[!, [:a]]) # single column branch
@test names(permutedims(df3[!, [:a]], makeunique=true)) == d3pd_names

df4 = DataFrame(a=rand(2), b=rand(2), c=[1, 2], d=[1., missing],
e=["x", "y"], f=[:x, :y], # valid src
Expand Down

0 comments on commit 040d856

Please sign in to comment.