Skip to content

Commit e3793ce

Browse files
authored
fix metadata handling in permutedims (#3176)
1 parent a3867e4 commit e3793ce

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/abstractdataframe/reshape.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,15 @@ function Base.permutedims(df::AbstractDataFrame, src_namescol::ColumnIndex;
851851
makeunique=makeunique, strict=strict)
852852
end
853853

854-
Base.permutedims(df::AbstractDataFrame) = DataFrame(permutedims(Matrix(df)), :auto)
855-
Base.permutedims(df::AbstractDataFrame, cnames::AbstractVector; makeunique::Bool=false) =
856-
DataFrame(permutedims(Matrix(df)), cnames, makeunique=makeunique)
854+
function Base.permutedims(df::AbstractDataFrame)
855+
out_df = DataFrame(permutedims(Matrix(df)), :auto)
856+
_copy_table_note_metadata!(out_df, df)
857+
return out_df
858+
end
859+
860+
function Base.permutedims(df::AbstractDataFrame, cnames::AbstractVector;
861+
makeunique::Bool=false)
862+
out_df = DataFrame(permutedims(Matrix(df)), cnames, makeunique=makeunique)
863+
_copy_table_note_metadata!(out_df, df)
864+
return out_df
865+
end

test/metadata.jl

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,27 +1373,29 @@ end
13731373
end
13741374

13751375
@testset "permutedims" begin
1376-
df = DataFrame(a=["x", "y"], b=[1.0, 2.0], c=[3, 4], d=[true, false])
1377-
res = permutedims(df, 1)
1378-
@test check_allnotemetadata(res)
1379-
@test getfield(res, :metadata) === nothing
1380-
@test getfield(res, :colmetadata) === nothing
1376+
for fun in (x -> permutedims(x, 1), permutedims, x -> permutedims(x, [:a, :b]))
1377+
df = DataFrame(a=["x", "y"], b=[1.0, 2.0], c=[3, 4], d=[true, false])
1378+
res = fun(df)
1379+
@test check_allnotemetadata(res)
1380+
@test getfield(res, :metadata) === nothing
1381+
@test getfield(res, :colmetadata) === nothing
13811382

1382-
metadata!(df, "name", "empty", style=:note)
1383-
metadata!(df, "name1", "empty1", style=:default)
1384-
colmetadata!(df, :a, "name", "a", style=:note)
1385-
colmetadata!(df, :a, "name1", "a1", style=:default)
1386-
colmetadata!(df, :b, "name", "b", style=:note)
1387-
colmetadata!(df, :b, "name1", "b1", style=:default)
1388-
colmetadata!(df, :c, "name", "c", style=:note)
1389-
colmetadata!(df, :c, "name1", "c1", style=:default)
1390-
colmetadata!(df, :d, "name", "d", style=:note)
1391-
colmetadata!(df, :d, "name1", "d1", style=:default)
1392-
res = permutedims(df, 1)
1393-
@test check_allnotemetadata(res)
1394-
@test collect(metadatakeys(res)) == ["name"]
1395-
@test metadata(res, "name") == "empty"
1396-
@test getfield(res, :colmetadata) === nothing
1383+
metadata!(df, "name", "empty", style=:note)
1384+
metadata!(df, "name1", "empty1", style=:default)
1385+
colmetadata!(df, :a, "name", "a", style=:note)
1386+
colmetadata!(df, :a, "name1", "a1", style=:default)
1387+
colmetadata!(df, :b, "name", "b", style=:note)
1388+
colmetadata!(df, :b, "name1", "b1", style=:default)
1389+
colmetadata!(df, :c, "name", "c", style=:note)
1390+
colmetadata!(df, :c, "name1", "c1", style=:default)
1391+
colmetadata!(df, :d, "name", "d", style=:note)
1392+
colmetadata!(df, :d, "name1", "d1", style=:default)
1393+
res = permutedims(df, 1)
1394+
@test check_allnotemetadata(res)
1395+
@test collect(metadatakeys(res)) == ["name"]
1396+
@test metadata(res, "name") == "empty"
1397+
@test getfield(res, :colmetadata) === nothing
1398+
end
13971399
end
13981400

13991401
@testset "broadcasting" begin

0 commit comments

Comments
 (0)