climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boust...@apache.org
Subject [1/4] git commit: CLIMATE-448 Use 'dateutil.relativedelta' to get 'next-month' datetime in decode_time_values' function and fixed unittest.
Date Thu, 29 May 2014 20:53:54 GMT
Repository: climate
Updated Branches:
  refs/heads/master 67fd821b2 -> fd6f97926


CLIMATE-448 Use 'dateutil.relativedelta' to get 'next-month' datetime in decode_time_values'
function and fixed unittest.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/32d648be
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/32d648be
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/32d648be

Branch: refs/heads/master
Commit: 32d648be0eb821cee5595d3ec632e2eaf9f84208
Parents: 23af110
Author: Maziyar Boustani <maziyar_b4@yahoo.com>
Authored: Thu May 29 13:09:03 2014 -0700
Committer: Maziyar Boustani <maziyar_b4@yahoo.com>
Committed: Thu May 29 13:09:03 2014 -0700

----------------------------------------------------------------------
 ocw/tests/test_utils.py | 4 ++--
 ocw/utils.py            | 5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/32d648be/ocw/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_utils.py b/ocw/tests/test_utils.py
index 6044d2f..48beb43 100644
--- a/ocw/tests/test_utils.py
+++ b/ocw/tests/test_utils.py
@@ -39,8 +39,8 @@ class TestDecodeTimes(unittest.TestCase):
         self.assertTrue(all([type(x) is datetime.datetime for x in times]))
 
     def test_valid_time_processing(self):
-        start_time = datetime.datetime.strptime('1988-06-10 00:00:00', '%Y-%m-%d %H:%M:%S')
-        end_time = datetime.datetime.strptime('2008-01-27 00:00:00', '%Y-%m-%d %H:%M:%S')
+        start_time = datetime.datetime.strptime('1989-01-01 00:00:00', '%Y-%m-%d %H:%M:%S')
+        end_time = datetime.datetime.strptime('2008-12-01 00:00:00', '%Y-%m-%d %H:%M:%S')
         times = utils.decode_time_values(self.netcdf, 'time')
 
         self.assertEquals(times[0], start_time)

http://git-wip-us.apache.org/repos/asf/climate/blob/32d648be/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index ec4a021..da3dcc1 100644
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -22,7 +22,7 @@ import datetime as dt
 import numpy as np
 
 from mpl_toolkits.basemap import shiftgrid
-
+from dateutil.relativedelta import relativedelta
 
 def decode_time_values(dataset, time_var_name):
     ''' Decode NetCDF time values into Python datetime objects.
@@ -50,8 +50,7 @@ def decode_time_values(dataset, time_var_name):
         # datetime.timedelta doesn't support a 'months' option. To remedy
         # this, a month == 30 days for our purposes.
         for time_val in time_data:
-            num_days = 30 * time_val
-            times.append(time_base + dt.timedelta(days=num_days))
+            times.append(time_base + relativedelta(months = int(time_val)))
     else:
         for time_val in time_data:
             arg[time_units] = time_val


Mime
View raw message