Hello,
I must be doing something wrong. Can someone explain this behavior to me?
module A
using DataFrames
x = DataFrame(a=[1,3],b=[4,3])
export x
end
module B
using ..A
function add_stuff(df)
df[:,:summed_cols] .= sum.(eachrow(df[:,1:2]))
return(df)
end
z = x
z = add_stuff(z)
end
module C
using ..A
x
end
running module A:
julia> A.x
2×2 DataFrame
Row │ a b
│ Int64 Int64
─────┼──────────────
1 │ 1 4
2 │ 3 3
^As expected
running module B:
julia> B.z
2×3 DataFrame
Row │ a b summed_cols
│ Int64 Int64 Int64
─────┼───────────────────────────
1 │ 1 4 5
2 │ 3 3 6
^ As expected
running module C:
julia> C.x
2×3 DataFrame
Row │ a b summed_cols
│ Int64 Int64 Int64
─────┼───────────────────────────
1 │ 1 4 5
2 │ 3 3 6
^^NOT EXPECTED
What is happening here? “x” wasn’t even modified in module B, as “z” was put through the function. Why doesn’t C.x look like A.x?
Also, why can module B modify X:
julia> B.x
2×3 DataFrame
Row │ a b summed_cols
│ Int64 Int64 Int64
─────┼───────────────────────────
1 │ 1 4 5
2 │ 3 3 6
But if I try to make a modification explicitly to x in the module, e.g.:
module B
using ..A
function add_stuff(df)
df[:,:summed_cols] .= sum.(eachrow(df[:,1:2]))
return(df)
end
z = x
z = add_stuff(z)
x = 3
end
I get the error:
ERROR: cannot assign a value to imported variable A.x from module B