Skip to content

When to use "deep copy"? (Doc string is over my head) #4962

Answered by max-sixty
michaelaye asked this question in Q&A
Discussion options

You must be logged in to vote

Others can give more precise definitions but my mental model:

  • .deepcopy copies everything that the object references. It shares nothing with the existing object.
  • .copy only copies the container. Anything that the existing object referenced will still be referenced by the new object.

One way to see this is to try copy and deepcopy-ing a dataset and see how these two respective operations on the copy are affected:

  • Assign an attrs
  • Mutate the underlying array; i.e. ds["lat"][0] = 1

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@max-sixty
Comment options

@keewis
Comment options

@max-sixty
Comment options

@keewis
Comment options

@dcherian
Comment options

Answer selected by max-sixty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants