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

remove last remnants of multi-index support

parent 08062bdfa5f4
......@@ -7,8 +7,6 @@ from sqlalchemy.dialects.postgresql import BYTEA, TIMESTAMP
from tshistory.util import (
fromjson,
mindate,
maxdate,
subset,
SeriesServices,
tojson
......@@ -84,8 +82,8 @@ class Snapshot(SeriesServices):
def insert_buckets(self, parent, buckets):
for bucket in buckets:
start = mindate(bucket)
end = maxdate(bucket)
start = bucket.index.min()
end = bucket.index.max()
sql = self.table.insert().values(
start=start,
end=end,
......@@ -111,13 +109,13 @@ class Snapshot(SeriesServices):
head = self.cn.execute(headsql).scalar()
# get raw chunks matching the limits
diffstart = mindate(diff)
diffstart = diff.index.min()
rawchunks = self.rawchunks(head, diffstart)
cid, parent, _ = rawchunks[0]
oldsnapshot = self._chunks_to_ts(row[2] for row in rawchunks)
if (len(oldsnapshot) >= self._min_bucket_size and
diffstart > maxdate(oldsnapshot)):
diffstart > oldsnapshot.index.max()):
# append: let't not rewrite anything
newsnapshot = diff
parent = cid
......
......@@ -11,8 +11,6 @@ from sqlalchemy.dialects.postgresql import BYTEA
from tshistory.schema import tsschema
from tshistory.util import (
inject_in_index,
mindate,
maxdate,
num2float,
subset,
SeriesServices,
......@@ -340,7 +338,9 @@ class TimeSerie(SeriesServices):
def _update(self, cn, table, newts, name, author, insertion_date=None):
self._validate(cn, newts, name)
snapshot = Snapshot(cn, self, name)
diff = self.diff(snapshot.last(mindate(newts), maxdate(newts)), newts)
diff = self.diff(snapshot.last(newts.index.min(),
newts.index.max()),
newts)
if not len(diff):
L.info('no difference in %s by %s (for ts of size %s)',
name, author or self._author, len(newts))
......
......@@ -6,27 +6,7 @@ import pandas as pd
from pandas.api.types import is_datetimetz
def mindate(ts):
if isinstance(ts.index, pd.MultiIndex):
return ts.index.min()[0]
return ts.index.min()
def maxdate(ts):
if isinstance(ts.index, pd.MultiIndex):
return ts.index.max()[0]
return ts.index.max()
def tzaware_serie(ts):
if isinstance(ts.index, pd.MultiIndex):
tzaware = [is_datetimetz(ts.index.get_level_values(idx_name))
for idx_name in ts.index.names]
assert all(tzaware) or not any(tzaware), (
'all your indexes must be '
'either tzaware or none of them'
)
return all(tzaware)
return is_datetimetz(ts.index)
......@@ -37,19 +17,10 @@ def subset(ts, fromdate, todate):
fromdate = fromdate[0]
if isinstance(todate, tuple):
todate = todate[0]
if isinstance(ts.index, pd.MultiIndex):
if not ts.index.lexsort_depth:
ts.sort_index(inplace=True)
return ts.loc[fromdate:todate]
def inject_in_index(serie, revdate):
if isinstance(serie.index, pd.MultiIndex):
mindex = [(revdate, *rest) for rest in serie.index]
serie.index = pd.MultiIndex.from_tuples(mindex, names=[
'insertion_date', *serie.index.names]
)
return
mindex = [(revdate, valuestamp) for valuestamp in serie.index]
serie.index = pd.MultiIndex.from_tuples(mindex, names=[
'insertion_date', 'value_date']
......@@ -64,12 +35,8 @@ def num2float(pdobj):
def tojson(ts, precision=1e-14):
if not isinstance(ts.index, pd.MultiIndex):
return ts.to_json(date_format='iso',
double_precision=-int(math.log10(precision)))
# multi index case
return ts.to_frame().reset_index().to_json(date_format='iso')
return ts.to_json(date_format='iso',
double_precision=-int(math.log10(precision)))
def fromjson(jsonb, tsname):
......
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