Commit 843090e9 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

validate: handle incompatible indexes

Normal vs Multi and Multi with differing names.
parent d3a9923766e7
......@@ -268,6 +268,26 @@ a b c
2017-10-29 01:00:00+00:00 2017-10-29 03:00:00+00:00 2017-10-29 07:00:00+00:00 8.0
""", ts)
ts = genserie(datetime(2010, 1, 1), 'D', 10)
with pytest.raises(Exception) as err:
tsh.insert(engine, ts, 'ts_multi_aware', 'test')
assert err.value.args[0] == 'Incompatible index types'
ts = genserie(
start=pd.Timestamp(
2017, 10, 28, 23
).tz_localize('UTC').tz_convert('Europe/Paris'),
freq=['15T', '30T'],
repeat=10,
tz='Europe/Paris',
name='ts_multi_aware',
)
ts.index.rename(['a', 'b'], inplace=True)
with pytest.raises(Exception) as err:
tsh.insert(engine, ts, 'ts_multi_aware', 'test')
assert err.value.args[0] == "Incompatible multi indexes: ['a', 'b', 'c'] vs ['a', 'b']"
def test_differential(engine, tsh):
ts_begin = genserie(datetime(2010, 1, 1), 'D', 10)
......
......@@ -581,6 +581,13 @@ class TimeSerie(object):
m = 'Type error when inserting {}, new type is {}, type in base is {}'.format(
name, new_type, old_type)
raise Exception(m)
if type(oldts.index) != type(newts.index):
raise Exception('Incompatible index types')
if isinstance(oldts.index, pd.MultiIndex):
if oldts.index.names != newts.index.names:
raise Exception('Incompatible multi indexes: {} vs {}'.format(
oldts.index.names, newts.index.names)
)
def _compute_diff_and_newsnapshot(self, cn, table, newts, **extra_scalars):
snapshot = self._build_snapshot_upto(cn, table)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment