From fdf4e9b7370f6c0d001cc533009f2a79d8821d63 Mon Sep 17 00:00:00 2001 From: Joe Jevnik Date: Fri, 13 Feb 2015 12:17:35 -0500 Subject: [PATCH] PERF: Makes get_datetime not make a copy. datetime.datetime objects are immutable. --- zipline/algorithm.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index fa6076f9..2e75dcee 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -809,16 +809,18 @@ class TradingAlgorithm(object): @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): """