Skip to content

deepcopy of Quantity discards units #27

Closed

Description

@ssalonen

I seems that copy.deepcopy() discards units of Quantity

Code example that illustrates the problem:

import quantities as pq
import copy
copy.deepcopy(3.5*pq.meter)
3.5

Activity

  1. lumbric commented on Aug 27, 2013

    @lumbric
    Contributor

    This issue seems to be caused by numpy:
    http://numpy-discussion.10968.n7.nabble.com/array-flags-not-copied-deepcopied-td31860.html

    Note that the copy argument of the Quantity is set to True by default. This argument is inherited from numpy. But this does not resolve the case where you have several nested dictionaries containing quantities and you need to copy it.

  2. xubuntix commented on Feb 20, 2014

    @xubuntix

    I think this happens, because quantities.Quantity does not define its own deepcopy method, but the one from numpy.ndarray is used (Quantity inherits from ndarray).
    Monkey Patching Quantitiy like this:

        quantities.Quantity.__deepcopy__ = lambda x,y: quantities.Quantity(x.magnitude, x.dimensionality)

    seems to help.

  3. added a commit that references this issue on Mar 23, 2014
    fc0e1ba
  4. lumbric commented on Mar 23, 2014

    @lumbric
    Contributor

    You are right. Ignore my last comment.

    I added a pull request in #78.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions