-
Notifications
You must be signed in to change notification settings - Fork 375
Closed
Description
This behavior of filter!()
caught me quite off-guard and took a while to debug:
julia> using DataFrames
julia> a = rand(10); b = rand(10); c = rand(10);
julia> df = DataFrame(x = a, y = b, z = c);
julia> df2 = copy(df[[2,3]]);
julia> filter!(row->row[:y] > 0.5, df2);
julia> df
10×3 DataFrame
│ Row │ x │ y │ z │
│ │ Float64 │ Float64 │ Float64 │
├─────┼───────────┼──────────┼────────────┤
│ 1 │ 0.0403589 │ 0.984833 │ 0.320714 │
│ 2 │ 0.221344 │ 0.949222 │ 0.0521154 │
│ 3 │ 0.245672 │ 0.659739 │ 0.400802 │
│ 4 │ 0.463964 │ 0.87275 │ 0.610431 │
│ 5 │ 0.0797766 │ 0.841099 │ 0.650547 │
│ 6 │ 0.0193848 │ 0.991481 │ 0.00325831 │
│ 7 │ 0.929879 │ #undef │ #undef │
│ 8 │ 0.611218 │ #undef │ #undef │
│ 9 │ 0.509054 │ #undef │ #undef │
│ 10 │ 0.381528 │ #undef │ #undef │
julia> b
6-element Array{Float64,1}:
0.9848328699008353
0.9492215902675882
0.6597386640528373
0.8727504349162607
0.8410991929844753
0.9914814768586502
I expected filter!()
on a DataFrame to only filter out rows on that DataFrame, not to modify the underlying arrays (which are shared across copies). The fix is to use deepcopy()
instead.
I'm not sure if this is something that should be "fixed", I think I understand the reasoning behind it, but at the very least I thought I'd open the issue for future stumblers on.
I think this is related to #1695
Metadata
Metadata
Assignees
Labels
No labels