Skip to content

Commit b35ca85

Browse files
committed
deepcopy in to_dict methods
1 parent ffa2453 commit b35ca85

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

pystac/catalog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
from copy import (deepcopy, copy)
34

45
from pystac import STACError
56
from pystac import STAC_VERSION
@@ -135,7 +136,7 @@ def to_dict(self, include_self_link=True):
135136
if self.title is not None:
136137
d['title'] = self.title
137138

138-
return d
139+
return deepcopy(d)
139140

140141
def clone(self):
141142
clone = Catalog(id=self.id,

pystac/collection.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import datetime
33
from datetime import timezone
44
import dateutil.parser
5-
from copy import copy
5+
from copy import (copy, deepcopy)
66
import json
77

88
from pystac import STACError, STAC_IO
@@ -62,7 +62,7 @@ def to_dict(self, include_self_link=True):
6262
if self.summaries is not None:
6363
d['summaries'] = self.summaries
6464

65-
return d
65+
return deepcopy(d)
6666

6767
def clone(self):
6868
clone = Collection(id=self.id,
@@ -139,11 +139,13 @@ def __init__(self, spatial, temporal):
139139
self.temporal = temporal
140140

141141
def to_dict(self):
142-
return {
142+
d = {
143143
'spatial': self.spatial.to_dict(),
144144
'temporal': self.temporal.to_dict()
145145
}
146146

147+
return deepcopy(d)
148+
147149
def clone(self):
148150
return Extent(spatial=copy(self.spatial),
149151
temporal=copy(self.temporal))
@@ -159,7 +161,8 @@ def __init__(self, bboxes):
159161
self.bboxes = bboxes
160162

161163
def to_dict(self):
162-
return { 'bbox' : self.bboxes }
164+
d = { 'bbox' : self.bboxes }
165+
return deepcopy(d)
163166

164167
def clone(self):
165168
return SpatialExtent(self.bboxes)
@@ -214,7 +217,8 @@ def to_dict(self):
214217

215218
encoded_intervals.append([start, end])
216219

217-
return { 'interval': encoded_intervals }
220+
d = {'interval': encoded_intervals}
221+
return deepcopy(d)
218222

219223
def clone(self):
220224
return TemporalExtent(intervals=copy(self.intervals))
@@ -256,7 +260,7 @@ def to_dict(self):
256260
if self.url is not None:
257261
d['url'] = self.url
258262

259-
return d
263+
return deepcopy(d)
260264

261265
@staticmethod
262266
def from_dict(d):

pystac/item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def to_dict(self, include_self_link=True):
7474

7575
assets = dict(map(lambda x: (x[0], x[1].to_dict()), self.assets.items()))
7676

77-
self.properties['datetime'] = self.datetime.isoformat()
77+
self.properties['datetime'] = '{}Z'.format(self.datetime.replace(microsecond=0, tzinfo=None))
7878

7979
d = {
8080
'type': 'Feature',
@@ -93,7 +93,7 @@ def to_dict(self, include_self_link=True):
9393
if self.collection:
9494
d['collection'] = self.collection
9595

96-
return d
96+
return deepcopy(d)
9797

9898
def clone(self):
9999
clone = Item(id=self.id,
@@ -223,7 +223,7 @@ def to_dict(self):
223223
for k, v in self.properties.items():
224224
d[k] = v
225225

226-
return d
226+
return deepcopy(d)
227227

228228
def clone(self):
229229
return Asset(href=self.href,

pystac/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def to_dict(self, include_self_link=True):
9292
if self.label_overviews is not None:
9393
d['properties']['label:overviews'] = [ov.to_dict() for ov in self.label_overviews]
9494

95-
return d
95+
return deepcopy(d)
9696

9797
def add_source(self, source_item, title=None, assets=None):
9898
properties = None

pystac/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from copy import copy
2+
from copy import (copy, deepcopy)
33
from urllib.parse import urlparse
44

55
from pystac import STACError
@@ -127,7 +127,7 @@ def to_dict(self):
127127
for k, v in self.properties.items():
128128
d[k] = v
129129

130-
return d
130+
return deepcopy(d)
131131

132132
def clone(self):
133133
return Link(rel=self.rel,

0 commit comments

Comments
 (0)