javascriptdata / danfojs

Danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.
https://danfo.jsdata.org/
MIT License
4.77k stars 209 forks source link

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

Open FunkMonkey opened 2 years ago

FunkMonkey commented 2 years ago

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.

nholmes3 commented 2 years ago

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 :)

SamuelNoB commented 1 year ago

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