Commit 31a14c4f authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

tsio/create: chop off those useless nans in the series boundaries

This is just a storage waste and it blurrs the start/end indices
used by the staircase queries.
parent 4eb0b7616eed
......@@ -433,7 +433,7 @@ def test_point_deletion(engine, tsh):
tsh.insert(engine, ts_begin, 'ts_del', 'test')
_, ts = Snapshot(engine, tsh, 'ts_del').find()
assert ts.iloc[-2] == 9.0
assert ts.iloc[-2] == 8.0
ts_begin.iloc[0] = np.nan
ts_begin.iloc[3] = np.nan
......@@ -1421,21 +1421,14 @@ def test_na(engine, tsh):
result = tsh.get(engine, 'test_nan', _keep_nans=True)
assert_df("""
2010-01-10 NaN
2010-01-11 NaN
2010-01-12 NaN
2010-01-13 3.0
2010-01-14 3.0
2010-01-15 3.0
2010-01-16 3.0
2010-01-17 3.0
2010-01-18 NaN
2010-01-19 NaN
""", result)
# the nans above are pretty useless
ival = tsh.interval(engine, 'test_nan')
# the interval boundaries are however right
assert ival.left == datetime(2010, 1, 13)
assert ival.right == datetime(2010, 1, 17)
......
......@@ -419,14 +419,16 @@ class TimeSerie(SeriesServices):
def _create(self, cn, newts, seriename, author,
metadata=None, insertion_date=None):
# initial insertion
if len(newts) == 0:
return None
start, end = start_end(newts)
start, end = start_end(newts, notz=False)
if start is None:
assert end is None
# this is just full of nans
return None
# chop off unwanted nans
newts = newts.loc[start:end]
if len(newts) == 0:
return None
# at creation time we take an exclusive lock to avoid
# a deadlock on created tables against the changeset-series fk
cn.execute(
......
......@@ -14,13 +14,13 @@ def tzaware_serie(ts):
return is_datetimetz(ts.index)
def start_end(ts):
def start_end(ts, notz=True):
ts = ts.dropna()
if not len(ts):
return None, None
start = ts.index.min()
end = ts.index.max()
if start.tzinfo is not None:
if start.tzinfo is not None and notz:
assert end.tzinfo is not None
start = start.tz_convert('UTC').replace(tzinfo=None)
end = end.tz_convert('UTC').replace(tzinfo=None)
......
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