danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

DataFrame.copy() does not make a deep copy of the data.

Open FunkMonkey opened this issue 2 years ago • 2 comments

Describe the bug DataFrame.copy() does not make a deep copy of the data, only a shallow copy!

The reason is the spread operation in copy(), which is used instead of a proper deep copy.

To Reproduce


const orig = new DataFrame(...);
const copy = orig.copy();
console.log(copy.values === orig.values); // logs false!
console.log(copy.values[0] === orig.values[0]); // logs true!

Expected behavior In the example above, the second console log should log false.

FunkMonkey avatar Jul 27 '22 17:07 FunkMonkey

I am having the same problem. I am currently getting around this with:

const copy = new dfd.DataFrame(dfd.toJSON(original));

although it would of course be preferable if the copy function behaved as documented :)

nholmes3 avatar Sep 07 '22 21:09 nholmes3

Almost One year later and this issue has not been fixed. Thanks @nholmes3 for te workaround!!

SamuelNoB avatar Aug 19 '23 21:08 SamuelNoB