drop pytimeparse requirement

use pandas timedelta as it offers comparable single item parsing
and better batch parsing

Change-Id: Ifd79385a4363ae4a9da5e9e94513ac98c7cdb1cb
This commit is contained in:
gord chung 2016-11-08 17:12:58 +00:00
parent 21966a74e9
commit 6959709196
4 changed files with 8 additions and 18 deletions

View File

@ -16,14 +16,13 @@
import datetime import datetime
import numpy import numpy
from oslo_utils import strutils
from oslo_utils import timeutils
import pandas import pandas
import six import six
from gnocchi import aggregates from gnocchi import aggregates
from gnocchi import utils
from oslo_utils import strutils
from oslo_utils import timeutils
from pytimeparse import timeparse
class MovingAverage(aggregates.CustomAggregator): class MovingAverage(aggregates.CustomAggregator):
@ -35,7 +34,7 @@ class MovingAverage(aggregates.CustomAggregator):
msg = 'Moving aggregate must have window specified.' msg = 'Moving aggregate must have window specified.'
raise aggregates.CustomAggFailure(msg) raise aggregates.CustomAggFailure(msg)
try: try:
return float(timeparse.timeparse(six.text_type(window))) return utils.to_timespan(six.text_type(window)).total_seconds()
except Exception: except Exception:
raise aggregates.CustomAggFailure('Invalid value for window') raise aggregates.CustomAggFailure('Invalid value for window')

View File

@ -46,14 +46,9 @@ class TestAggregates(tests_base.TestCase):
self.assertEqual(60.0, result) self.assertEqual(60.0, result)
window = '60' window = '60'
self.assertRaises(aggregates.CustomAggFailure, agg_obj = self.custom_agg[agg_method]
agg_obj.check_window_valid, result = agg_obj.check_window_valid(window)
window) self.assertEqual(60.0, result)
window = None
self.assertRaises(aggregates.CustomAggFailure,
agg_obj.check_window_valid,
window)
def _test_create_metric_and_data(self, data, spacing): def _test_create_metric_and_data(self, data, spacing):
metric = storage.Metric( metric = storage.Metric(

View File

@ -22,7 +22,6 @@ import iso8601
import numpy import numpy
from oslo_utils import timeutils from oslo_utils import timeutils
import pandas as pd import pandas as pd
from pytimeparse import timeparse
import six import six
import tenacity import tenacity
import uuid import uuid
@ -116,11 +115,9 @@ def to_timespan(value):
seconds = float(value) seconds = float(value)
except Exception: except Exception:
try: try:
seconds = timeparse.timeparse(six.text_type(value)) seconds = pd.Timedelta(six.text_type(value)).total_seconds()
except Exception: except Exception:
raise ValueError("Unable to parse timespan") raise ValueError("Unable to parse timespan")
if seconds is None:
raise ValueError("Unable to parse timespan")
if seconds <= 0: if seconds <= 0:
raise ValueError("Timespan must be positive") raise ValueError("Timespan must be positive")
return datetime.timedelta(seconds=seconds) return datetime.timedelta(seconds=seconds)

View File

@ -9,7 +9,6 @@ oslo.utils>=3.18.0
oslo.middleware>=3.11.0 oslo.middleware>=3.11.0
pandas>=0.17.0 pandas>=0.17.0
pecan>=0.9 pecan>=0.9
pytimeparse>=1.1.5
futures futures
jsonpatch jsonpatch
cotyledon>=1.5.0 cotyledon>=1.5.0