Skip to content

Commit

Permalink
PERF: Makes get_datetime not make a copy.
Browse files Browse the repository at this point in the history
datetime.datetime objects are immutable.
  • Loading branch information
Joe Jevnik committed Feb 17, 2015
1 parent 556c5a8 commit fdf4e9b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions zipline/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,16 +809,18 @@ def on_dt_changed(self, dt):
@api_method
def get_datetime(self, tz=None):
"""
Returns a copy of the datetime.
Returns the simulation datetime.
"""
date_copy = copy(self.datetime)
assert date_copy.tzinfo == pytz.utc, \
"Algorithm should have a utc datetime"
dt = self.datetime
assert dt.tzinfo == pytz.utc, "Algorithm should have a utc datetime"

if tz is not None:
# Convert to the given timezone passed as a string or tzinfo.
if isinstance(tz, string_types):
tz = pytz.timezone(tz)
date_copy = date_copy.astimezone(tz)
return date_copy
dt = dt.astimezone(tz)

return dt # datetime.datetime objects are immutable.

def set_transact(self, transact):
"""
Expand Down

0 comments on commit fdf4e9b

Please sign in to comment.