Commit cf880515 authored by Arnaud Campeas's avatar Arnaud Campeas
Browse files

tsio: an insertion of Nan will mask the underlying data

parent 7128fb37d184
......@@ -435,3 +435,87 @@ def test_snapshots(engine):
snapid, snap = tso._find_snapshot(engine, table, ())
assert snapid == 10
assert (ts == snap).all()
def test_deletion(engine):
tso = TimeSerie()
ts_begin = pd.Series(range(10))
ts_begin.index = pd.date_range(start=datetime(2010, 1, 1), freq='D', periods=10)
tso.insert(engine, ts_begin, 'ts_del', 'test')
ts_begin.iloc[3] = np.nan
ts_begin.iloc[0] = np.nan
tso.insert(engine, ts_begin, 'ts_del', 'test')
assert """
2010-01-02 1.0
2010-01-03 2.0
2010-01-05 4.0
2010-01-06 5.0
2010-01-07 6.0
2010-01-08 7.0
2010-01-09 8.0
2010-01-10 9.0""".strip() == tso.get(engine, 'ts_del').to_string().strip()
ts_begin.iloc[0] = 42
ts_begin.iloc[3] = 23
tso.insert(engine, ts_begin, 'ts_del', 'test')
assert """
2010-01-01 42.0
2010-01-02 1.0
2010-01-03 2.0
2010-01-04 23.0
2010-01-05 4.0
2010-01-06 5.0
2010-01-07 6.0
2010-01-08 7.0
2010-01-09 8.0
2010-01-10 9.0""".strip() == tso.get(engine, 'ts_del').to_string().strip()
# now with string!
ts_string = pd.Series(['machin'] * 10)
ts_string.index = pd.date_range(start=datetime(2010, 1, 1), freq='D', periods=10)
tso.insert(engine, ts_string, 'ts_string_del', 'test')
ts_string[4] = None
ts_string[5] = None
tso.insert(engine, ts_string, 'ts_string_del', 'test')
assert"""
2010-01-01 machin
2010-01-02 machin
2010-01-03 machin
2010-01-04 machin
2010-01-07 machin
2010-01-08 machin
2010-01-09 machin
2010-01-10 machin
""".strip() == tso.get(engine, 'ts_string_del').to_string().strip()
ts_string[4] = 'truc'
ts_string[6] = 'truc'
tso.insert(engine, ts_string, 'ts_string_del', 'test')
assert """
2010-01-01 machin
2010-01-02 machin
2010-01-03 machin
2010-01-04 machin
2010-01-05 truc
2010-01-07 truc
2010-01-08 machin
2010-01-09 machin
2010-01-10 machin""".strip() == tso.get(engine, 'ts_string_del').to_string().strip()
# first insertion with only nan
ts_begin = pd.Series([np.nan] * 10)
ts_begin.index = pd.date_range(start=datetime(2010, 1, 1), freq='D', periods=10)
tso.insert(engine, ts_begin, 'ts_null', 'test')
assert tso.get(engine, 'ts_null') is None
......@@ -74,7 +74,7 @@ class TimeSerie(object):
if str(newts.dtype).startswith('int'):
newts = newts.astype('float64')
newts = newts[~newts.isnull()] # wipe the the NaNs
if not len(newts):
return
......@@ -83,6 +83,8 @@ class TimeSerie(object):
if table is None:
# initial insertion
if newts.isnull().all():
return None
table = self._make_ts_table(cnx, name)
csid = self._csid or self._newchangeset(cnx, author)
value = {
......@@ -331,9 +333,6 @@ class TimeSerie(object):
"""Compute the difference between fromts and tots
(like in tots - fromts).
Deletions are not handled. New lines in tots and lines that
changed in tots relatively to tots will appear in the diff.
"""
if fromts is None or not len(fromts):
return tots
......@@ -364,5 +363,6 @@ class TimeSerie(object):
result_ts = pd.Series([0.0], index=base_ts.index.union(new_ts.index))
result_ts[base_ts.index] = base_ts
result_ts[new_ts.index] = new_ts
result_ts = result_ts[~result_ts.isnull()]
result_ts.sort_index(inplace=True)
return result_ts
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