Skip to content
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

Column metadata anchored to wrong column after insertion of new colums #3218

Closed
mathieu17g opened this issue Nov 8, 2022 · 4 comments · Fixed by #3220
Closed

Column metadata anchored to wrong column after insertion of new colums #3218

mathieu17g opened this issue Nov 8, 2022 · 4 comments · Fixed by #3220
Labels
Milestone

Comments

@mathieu17g
Copy link

Hello,

I stumbled on an issue where colmetadata are not translated with the column tafter inserting a new column before.
I have not found this issue mentionned amond recent issues with the metadata keyword.

Here is an example to reproduce it:

julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf26 (2022-09-29 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i5-10400H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, skylake)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

(myproject) pkg> status DataFrames
Project myproject v0.1.0
Status `C:\...\code_julia\myproject\Project.toml`
  [a93c6f00] DataFrames v1.4.2

julia> df = DataFrame(B=[1, 2], C=[3.0, 4.0])
2×2 DataFrame
 Row │ B      C       
     │ Int64  Float64 
─────┼────────────────
   11      3.0
   22      4.0

julia> colmetadata!(df, :C, "label", "last column"; style=:note)
2×2 DataFrame
 Row │ B      C       
     │ Int64  Float64 
─────┼────────────────
   11      3.0
   22      4.0

julia> colmetadatakeys(df) |> collect
1-element Vector{Pair{Symbol, Base.KeySet{String, Dict{String, Tuple{Any, Any}}}}}:
 :C => ["label"]

julia> insertcols!(df, 1, :A => ["a", "b"])
2×3 DataFrame
 Row │ A       B      C       
     │ String  Int64  Float64 
─────┼────────────────────────
   1 │ a           1      3.0
   2 │ b           2      4.0

julia> colmetadatakeys(df) |> collect
1-element Vector{Pair{Symbol, Base.KeySet{String, Dict{String, Tuple{Any, Any}}}}}:
 :B => ["label"]
julia> 
@mathieu17g
Copy link
Author

The testset on functions that should not affect metadata in test/metadata.jl, tests only the insertion of a column at the end:

x -> insertcols!(x, :newcol => 1, makeunique=true),

@mathieu17g
Copy link
Author

Maybe the issue is linked with the fact that colmetadata are indexes by column number in DataFrame struct

mutable struct DataFrame <: AbstractDataFrame
columns::Vector{AbstractVector}
colindex::Index
metadata::Union{Nothing, Dict{String, Tuple{Any, Any}}}
colmetadata::Union{Nothing, Dict{Int, Dict{String, Tuple{Any, Any}}}}

And that there is no insertion routine in insertcols! on colmetadata, as there is on Index and Columns

insert!(index(dfp), col_ind, name)
insert!(_columns(dfp), col_ind, item_new)

@bkamins bkamins added the bug label Nov 8, 2022
@bkamins bkamins added this to the patch milestone Nov 8, 2022
@bkamins
Copy link
Member

bkamins commented Nov 8, 2022

This is a bug. I will fix it. Thank you for reporting.

@bkamins
Copy link
Member

bkamins commented Nov 8, 2022

Fixed in #3220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants