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:
parent
21966a74e9
commit
6959709196
|
@ -16,14 +16,13 @@
|
|||
import datetime
|
||||
|
||||
import numpy
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
import pandas
|
||||
import six
|
||||
|
||||
from gnocchi import aggregates
|
||||
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from pytimeparse import timeparse
|
||||
from gnocchi import utils
|
||||
|
||||
|
||||
class MovingAverage(aggregates.CustomAggregator):
|
||||
|
@ -35,7 +34,7 @@ class MovingAverage(aggregates.CustomAggregator):
|
|||
msg = 'Moving aggregate must have window specified.'
|
||||
raise aggregates.CustomAggFailure(msg)
|
||||
try:
|
||||
return float(timeparse.timeparse(six.text_type(window)))
|
||||
return utils.to_timespan(six.text_type(window)).total_seconds()
|
||||
except Exception:
|
||||
raise aggregates.CustomAggFailure('Invalid value for window')
|
||||
|
||||
|
|
|
@ -46,14 +46,9 @@ class TestAggregates(tests_base.TestCase):
|
|||
self.assertEqual(60.0, result)
|
||||
|
||||
window = '60'
|
||||
self.assertRaises(aggregates.CustomAggFailure,
|
||||
agg_obj.check_window_valid,
|
||||
window)
|
||||
|
||||
window = None
|
||||
self.assertRaises(aggregates.CustomAggFailure,
|
||||
agg_obj.check_window_valid,
|
||||
window)
|
||||
agg_obj = self.custom_agg[agg_method]
|
||||
result = agg_obj.check_window_valid(window)
|
||||
self.assertEqual(60.0, result)
|
||||
|
||||
def _test_create_metric_and_data(self, data, spacing):
|
||||
metric = storage.Metric(
|
||||
|
|
|
@ -22,7 +22,6 @@ import iso8601
|
|||
import numpy
|
||||
from oslo_utils import timeutils
|
||||
import pandas as pd
|
||||
from pytimeparse import timeparse
|
||||
import six
|
||||
import tenacity
|
||||
import uuid
|
||||
|
@ -116,11 +115,9 @@ def to_timespan(value):
|
|||
seconds = float(value)
|
||||
except Exception:
|
||||
try:
|
||||
seconds = timeparse.timeparse(six.text_type(value))
|
||||
seconds = pd.Timedelta(six.text_type(value)).total_seconds()
|
||||
except Exception:
|
||||
raise ValueError("Unable to parse timespan")
|
||||
if seconds is None:
|
||||
raise ValueError("Unable to parse timespan")
|
||||
if seconds <= 0:
|
||||
raise ValueError("Timespan must be positive")
|
||||
return datetime.timedelta(seconds=seconds)
|
||||
|
|
|
@ -9,7 +9,6 @@ oslo.utils>=3.18.0
|
|||
oslo.middleware>=3.11.0
|
||||
pandas>=0.17.0
|
||||
pecan>=0.9
|
||||
pytimeparse>=1.1.5
|
||||
futures
|
||||
jsonpatch
|
||||
cotyledon>=1.5.0
|
||||
|
|
Loading…
Reference in New Issue