Commit 2156fd9e authored by Arnaud Campeas's avatar Arnaud Campeas
Browse files

tsio: ensure the NaNs inserted when there is no previous value are discarded

parent 81b42ca9e091
......@@ -668,3 +668,31 @@ a b c
""", pd.DataFrame(ts.sort_index()))
# the result ts have now 3 values for each point in 'a'
def test_add_na(engine):
tso = TimeSerie()
# a serie of NaNs won't be insert in base
# in case of first insertion
ts_nan = genserie(datetime(2010, 1, 1), 'D', 5)
ts_nan[[True] * len(ts_nan)] = np.nan
diff = tso.insert(engine, ts_nan, 'ts_add_na', 'test')
assert diff is None
result = tso.get(engine, 'ts_add_na')
assert result is None
# in case of insertion in existing data
ts_begin = genserie(datetime(2010, 1, 1), 'D', 5)
tso.insert(engine, ts_begin, 'ts_add_na', 'test')
ts_nan = genserie(datetime(2010, 1, 6), 'D', 5)
ts_nan[[True] * len(ts_nan)] = np.nan
ts_nan = pd.concat([ts_begin, ts_nan])
diff = tso.insert(engine, ts_nan, 'ts_add_na', 'test')
assert diff is None
result = tso.get(engine, 'ts_add_na')
assert len(result) == 5
......@@ -359,6 +359,7 @@ class TimeSerie(object):
diff_overlap = tots[mask_overlap][~mask_equal]
diff_new = tots[~mask_overlap]
diff_new = diff_new[~diff_new.isnull()]
return pd.concat([diff_overlap, diff_new])
def _apply_diff(self, base_ts, new_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