Reputation: 257
Consider the following code, where I want to change only 1 cell, but the entire row gets changed:
df=DataFrames.DataFrame(A=[1,2],B=[3,4])
df[2,:A]=7 # this is OK, changes only 1 cell
df[:,1:end]=0.0 # this line somehow makes the change in the next line behave unexpectedly
df[2,:A]=7 # entire 2nd row is 7
It's as if the df[:,1:end]=0.0
sets all the cells of that row to the same reference; but I am setting it to 0.0, so I expect this to be a value copy, not reference copy
Versions: julia version 0.4.6-pre DataFrames v"0.7.8"
Upvotes: 7
Views: 984
Reputation: 12061
There's some aliasing going on here. I think this is a bug in DataFrames
, though it's possible that it's intended behaviour, albeit strange. What's happening is that the same underlying data is being used by both columns. See #1052.
As a workaround, you can set the columns one by one:
for c in 1:size(df, 2)
df[:,c] = 0.0
end
Upvotes: 4