rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
262 stars 38 forks source link

Copy of Dictionary of DimArrays creates views #709

Closed alex-s-gardner closed 1 month ago

alex-s-gardner commented 1 month ago

This behaviour surprised me:

copy of DimArray preforms as expected:

A = DimArray(fill(NaN, length(x), length(y)), (x=x, y=y))
B = copy(A)
A[1, 1] #NaN
B[1,1] = 100.
A[1, 1] # NaN

copy of a Dictionary of DimArrays does not preform as expected:

# create a dictionary of DimArrays
A = Dict();
items = ["a", "b", "c"];
x = 1:10;
y = 1:10;
for item in items
    push!(A, item => DimArray(fill(NaN, length(x), length(y)), (x=x, y=y)))
end;

# copy A
B = copy(A);

A["a"][1,1] # NaN
B["a"][1, 1] = 100.0;
A["a"][1, 1] # 100.0
rafaqz commented 1 month ago

You may be looking fo deepcopy ;)

This is what copy is meant to do.

alex-s-gardner commented 1 month ago

I am indeed.. thanks