nanophotonics/nplab

ArrayWithAttrs doesn't copy attrs dictionary

Closed this issue · 2 comments

rwb27 commented

When copying/creating new ArrayWithAttrs objects, the attrs dictionary is sometimes shared between the copies (e.g. if you slice an ArrayWithAttrs). This can cause very odd behaviour if you're not expecting it.

rwb27 commented

I've amended the code so that in aray_finalize it always copies the attributes dictionary.

rwb27 commented

Interestingly, copying the attrs dictionary doesn't always solve the problem; if you've got numpy ndarrays in there, they don't get copied (as the dict only stores a reference to them). I've explicitly copied all the ndarray objects (and subclasses) to get around this.