@@ 121,7 121,6 @@ 2018-01-01 00:00:00+00:00 0.0
assert ts.name == 'test'
meta = client.metadata('test', all=True)
- meta.pop('supervision_status')
assert meta == {
'tzaware': True,
'index_type': 'datetime64[ns, UTC]',
@@ 478,96 477,6 @@ 2020-01-05 00:00:00+00:00 4.0
}]
-def test_formula(client, engine, tsh):
- tsh.update(
- engine,
- pd.Series(
- [1, 2, 3],
- index=pd.date_range(
- pd.Timestamp('2020-1-1', tz='UTC'),
- freq='D',
- periods=3
- )
- ),
- 'in-a-formula',
- 'Babar'
- )
-
- with pytest.raises(SyntaxError):
- client.register_formula(
- 'new-formula',
- '(+ 3'
- )
-
- with pytest.raises(ValueError):
- client.register_formula(
- 'new-formula',
- '(+ 3 (series "lol"))'
- )
-
- client.register_formula(
- 'new-formula',
- '(+ 3 (series "lol"))',
- reject_unknown=False
- )
-
-
- with pytest.raises(AssertionError):
- client.register_formula(
- 'new-formula',
- '(+ 3 (series "in-a-formula"))',
- )
-
-
- client.register_formula(
- 'new-formula',
- '(+ 3 (series "in-a-formula"))',
- update=True
- )
-
- series = client.get('new-formula')
- assert_df("""
-2020-01-01 00:00:00+00:00 4.0
-2020-01-02 00:00:00+00:00 5.0
-2020-01-03 00:00:00+00:00 6.0
-""", series)
-
- assert client.formula('new-formula') == '(+ 3 (series "in-a-formula"))'
- assert client.formula('lol') is None
-
- client.register_formula(
- '2-levels',
- '(+ 5 (series "new-formula"))'
- )
- assert client.formula('2-levels', True) == '(+ 5 (+ 3 (series "in-a-formula")))'
-
- assert client.formula_components('2-levels', True) == (
- {'2-levels': [{'new-formula': ['in-a-formula']}]}
- )
-
-
-def test_supervision(client, engine):
- series = genserie(utcdt(2020, 1, 1), 'D', 3)
- client.update('test-supervision', series, 'Babar')
-
- series[-1] = 42
- client.update('test-supervision', series, 'Babar', manual=True)
-
- ts, markers = client.edited('test-supervision')
-
- assert_df("""
-2020-01-01 00:00:00+00:00 0.0
-2020-01-02 00:00:00+00:00 1.0
-2020-01-03 00:00:00+00:00 42.0
-""", ts)
-
- assert_df("""
-2020-01-01 00:00:00+00:00 False
-2020-01-02 00:00:00+00:00 False
-2020-01-03 00:00:00+00:00 True
-""", markers)
-
-
def test_multisources(client, engine):
series = genserie(utcdt(2020, 1, 1), 'D', 3)
tsh = tsio.timeseries('other')
@@ 594,11 503,7 @@ def test_multisources(client, engine):
['staircase', 'primary'],
['staircase-naive', 'primary'],
['test-log', 'primary'],
- ['in-a-formula', 'primary'],
- ['test-supervision', 'primary'],
['test-mainsource', 'primary'],
- ['new-formula', 'formula'],
- ['2-levels', 'formula']
]
}
cat = client.catalog(allsources=False)
@@ 636,137 541,3 @@ def test_stored_groups(client):
assert not client.group_exists('test_group')
-def test_group_formula(client):
- df = gengroup(
- n_scenarios=3,
- from_date=dt.datetime(2021, 1, 1),
- length=5,
- freq='D',
- seed=2.
- )
- df.columns = ['a', 'b', 'c']
-
- client.group_replace('for_a_group_formula', df, 'Babar')
-
- client.register_group_formula(
- 'test_group_formula',
- '(group "for_a_group_formula")'
- )
- assert client.group_exists('test_group_formula')
-
- df2 = client.group_get('test_group_formula')
- assert df2.equals(df)
-
- assert client.group_formula('test_group_formula') == '(group "for_a_group_formula")'
- client.update_group_metadata('test_group_formula', {'foo': 'bar'})
- assert client.group_metadata('test_group_formula') == {'foo': 'bar'}
-
- client.group_delete('test_group_formula')
- assert not client.group_exists('test_group_formula')
-
-
-def test_bound_formula(client):
- temp = pd.Series(
- [12, 13, 14],
- index=pd.date_range(utcdt(2021, 1, 1), freq='D', periods=3)
- )
- wind = pd.Series(
- [.1, .1, .1],
- index=pd.date_range(utcdt(2021, 1, 1), freq='D', periods=3)
- )
-
- client.update('base-temp', temp, 'Babar')
- client.update('base-wind', wind, 'Celeste')
-
- client.register_formula(
- 'hijacked',
- '(add (series "base-temp") (series "base-wind"))'
- )
-
- df1 = gengroup(
- n_scenarios=2,
- from_date=dt.datetime(2021, 1, 1),
- length=3,
- freq='D',
- seed=0
- )
- client.group_replace(
- 'temp-ens',
- df1,
- 'Arthur'
- )
- assert_df("""
- 0 1
-2021-01-01 0 1
-2021-01-02 1 2
-2021-01-03 2 3
-""", df1)
-
- df2 = gengroup(
- n_scenarios=2,
- from_date=dt.datetime(2021, 1, 1),
- length=3,
- freq='D',
- seed=1
- )
- client.group_replace(
- 'wind-ens',
- df2,
- 'Zéphir'
- )
- assert_df("""
- 0 1
-2021-01-01 1 2
-2021-01-02 2 3
-2021-01-03 3 4
-""", df2)
-
- binding = pd.DataFrame(
- [
- ['base-temp', 'temp-ens', 'meteo'],
- ['base-wind', 'wind-ens', 'meteo'],
- ],
- columns=('series', 'group', 'family')
- )
-
- client.register_formula_bindings(
- 'hijacking',
- 'hijacked',
- binding
- )
-
- b = client.bindings_for('hijacking')
- for attr in ('series', 'group', 'family'):
- assert b[1][attr].equals(binding[attr])
-
- ts = client.get('hijacked')
- assert_df("""
-2021-01-01 00:00:00+00:00 12.1
-2021-01-02 00:00:00+00:00 13.1
-2021-01-03 00:00:00+00:00 14.1
-""", ts)
-
- df = client.group_get('hijacking')
- assert_df("""
- 0 1
-2021-01-01 1.0 3.0
-2021-01-02 3.0 5.0
-2021-01-03 5.0 7.0
-""", df)
-
- assert client.group_exists('hijacking')
- assert client.group_type('hijacking') == 'bound'
-
- cat = list(client.group_catalog().values())[0]
- assert ('hijacking', 'bound') in cat
-
- assert client.group_metadata('hijacking') == {}
- client.update_group_metadata('hijacking', {'foo': 'bar'})
- assert client.group_metadata('hijacking') == {'foo': 'bar'}
-
- client.group_delete('hijacking')
- assert not client.group_exists('hijacking')
-
- assert client.group_metadata('hijacking') is None
- with pytest.raises(AssertionError):
- client.update_group_metadata('hijacking', {'foo': 'bar'})
@@ 171,32 171,6 @@ class Client:
return res
@unwraperror
- def edited(self, name,
- revision_date=None,
- from_value_date=None,
- to_value_date=None):
- args = {
- 'name': name,
- 'format': 'tshpack',
- }
- if revision_date:
- args['insertion_date'] = strft(revision_date)
- if from_value_date:
- args['from_value_date'] = strft(from_value_date)
- if to_value_date:
- args['to_value_date'] = strft(to_value_date)
- res = requests.get(
- f'{self.uri}/series/supervision', params=args
- )
- if res.status_code == 404:
- return None
- if res.status_code == 200:
- series, markers = unpack_many_series(res.content)
- return series, markers
-
- return res
-
- @unwraperror
def insertion_dates(self, name,
from_insertion_date=None,
to_insertion_date=None):
@@ 378,63 352,6 @@ class Client:
return res
- # formula
-
- @unwraperror
- def formula(self, name, expanded=False):
- res = requests.get(
- f'{self.uri}/series/formula', params={
- 'name': name,
- 'expanded': expanded
- }
- )
- if res.status_code == 200:
- return res.json()
- if res.status_code == 418:
- return res
- return # None is the reasonable api answer
-
- @unwraperror
- def formula_components(self, name, expanded=False):
- res = requests.get(
- f'{self.uri}/series/formula_components', params={
- 'name': name,
- 'expanded': expanded
- }
- )
- if res.status_code == 200:
- return res.json()
- if res.status_code == 418:
- return res
- return # None is the reasonable api answer
-
- @unwraperror
- def register_formula(self, name,
- formula,
- reject_unknown=True,
- update=False):
- res = requests.patch(
- f'{self.uri}/series/formula', data={
- 'name': name,
- 'text': formula,
- 'reject_unknown': reject_unknown,
- 'force_update': update
- }
- )
- if res.status_code == 400:
- raise SyntaxError(res.json()['message'])
- elif res.status_code == 409:
- msg = res.json()['message']
- if 'unknown' in msg:
- raise ValueError(msg)
- elif 'exists' in msg:
- raise AssertionError(msg)
-
- if res.status_code in (200, 204):
- return
-
- return res
-
# groups
@unwraperror
@@ 565,70 482,3 @@ class Client:
return
return res
-
- @unwraperror
- def group_formula(self, name, expanded=False):
- res = requests.get(
- f'{self.uri}/group/formula', params={
- 'name': name,
- 'expanded': expanded
- }
- )
- if res.status_code == 200:
- return res.json()
- if res.status_code == 418:
- return res
- if res.status_code == 404:
- return
- return res
-
- @unwraperror
- def register_group_formula(self, name, formula):
- res = requests.put(
- f'{self.uri}/group/formula', data={
- 'name': name,
- 'text': formula
- }
- )
- if res.status_code == 400:
- raise SyntaxError(res.json()['message'])
- elif res.status_code == 409:
- msg = res.json()['message']
- if 'unknown' in msg:
- raise ValueError(msg)
- elif 'exists' in msg:
- raise AssertionError(msg)
- else:
- raise TypeError(msg)
-
- if res.status_code in (200, 204):
- return
-
- return res
-
- @unwraperror
- def register_formula_bindings(self, name, formulaname, bindings):
- res = requests.put(
- f'{self.uri}/group/boundformula', data={
- 'name': name,
- 'formulaname': formulaname,
- 'bindings': bindings.to_json(orient='records')
- }
- )
- return res
-
- @unwraperror
- def bindings_for(self, name):
- res = requests.get(
- f'{self.uri}/group/boundformula', params={
- 'name': name
- }
- )
- if res.status_code == 200:
- name, bindings = res.json()
- return name, pd.DataFrame(bindings)
-
- if res.status_code == 404:
- return None
-
- return res