Skip to content

Commit 7945d40

Browse files
mhvkembray
authored andcommitted
Merge pull request #1961 from ryanfox/wrap-angle-pickling
Fix for #1942. Added pickling test class for coordinates as well
1 parent bda0fc8 commit 7945d40

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from ...extern.six.moves import cPickle as pickle
2+
from ...coordinates import Longitude
3+
4+
def test_basic():
5+
lon1 = Longitude(1.23, "radian", wrap_angle='180d')
6+
s = pickle.dumps(lon1)
7+
lon2 = pickle.loads(s)
8+
9+
def test_pickle_longitude_wrap_angle():
10+
a = Longitude(1.23, "radian", wrap_angle='180d')
11+
s = pickle.dumps(a)
12+
b = pickle.loads(s)
13+
14+
assert a.rad == b.rad
15+
assert a.wrap_angle == b.wrap_angle

‎astropy/units/quantity.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,17 @@ def __reduce__(self):
394394
# patch to pickle Quantity objects (ndarray subclasses),
395395
# see http://www.mail-archive.com/[email protected]/msg02446.html
396396

397-
object_state = list(np.ndarray.__reduce__(self))
398-
subclass_state = (self._unit,)
399-
object_state[2] = (object_state[2], subclass_state)
397+
object_state = list(super(Quantity, self).__reduce__())
398+
object_state[2] = (object_state[2], self.__dict__)
400399
return tuple(object_state)
401400

402401
def __setstate__(self, state):
403402
# patch to unpickle Quantity objects (ndarray subclasses),
404403
# see http://www.mail-archive.com/[email protected]/msg02446.html
405404

406405
nd_state, own_state = state
407-
np.ndarray.__setstate__(self, nd_state)
408-
409-
unit, = own_state
410-
self._unit = unit
406+
super(Quantity, self).__setstate__(nd_state)
407+
self.__dict__.update(own_state)
411408

412409
def to(self, unit, equivalencies=[]):
413410
""" Returns a new `Quantity` object with the specified units.

0 commit comments

Comments
 (0)