Commit 5a21966d authored by Arnaud Campeas's avatar Arnaud Campeas
Browse files

remove unnecessary subset function inherited from multi-index handling

parent c05f426b16be
......@@ -275,6 +275,35 @@ def test_differential(engine, tsh):
2010-01-07 3.0
""", tsh.get(engine, 'ts_mixte'))
assert_df("""
2010-01-03 2.0
2010-01-04 -1.0
2010-01-05 2.0
2010-01-06 2.0
""", tsh.get(engine, 'ts_mixte',
from_value_date=datetime(2010, 1, 3),
to_value_date=datetime(2010, 1, 6)
))
assert_df("""
2010-01-04 -1.0
2010-01-05 2.0
2010-01-06 2.0
2010-01-07 3.0
""", tsh.get(engine, 'ts_mixte',
from_value_date=datetime(2010, 1, 4)
))
assert_df("""
2010-01-01 2.0
2010-01-02 2.0
2010-01-03 2.0
2010-01-04 -1.0
2010-01-05 2.0
""", tsh.get(engine, 'ts_mixte',
to_value_date=datetime(2010, 1, 5)
))
with engine.begin() as cn:
cn.execute('set search_path to "{0}.timeserie", {0}, public'.format(tsh.namespace))
allts = pd.read_sql("select seriename, table_name from registry "
......
......@@ -11,7 +11,6 @@ from sqlalchemy.sql.expression import select, asc, desc
from sqlalchemy.dialects.postgresql import BYTEA, TIMESTAMP
from tshistory.util import (
subset,
SeriesServices
)
......@@ -219,9 +218,7 @@ class Snapshot(SeriesServices):
snapdata = self._chunks_to_ts(
raw[2] for raw in self.rawchunks(head, from_value_date)
)
return subset(snapdata,
from_value_date, to_value_date
)
return snapdata.loc[from_value_date:to_value_date]
def last(self, from_value_date=None, to_value_date=None):
return self.find(from_value_date=from_value_date,
......@@ -307,9 +304,9 @@ class Snapshot(SeriesServices):
chunks.append(chunk)
head = parent
series.append(
(idate, subset(self._chunks_to_ts(reversed(chunks)),
from_value_date,
to_value_date)
(idate, self._chunks_to_ts(reversed(chunks)).loc[
from_value_date:to_value_date
]
)
)
return series
......@@ -13,7 +13,6 @@ from tshistory.schema import tsschema
from tshistory.util import (
closed_overlaps,
num2float,
subset,
SeriesServices,
start_end,
tzaware_serie
......@@ -267,7 +266,7 @@ class TimeSerie(SeriesServices):
vimap[vdate] = idate
vvmap[vdate] = value
ts = subset(pd.Series(vvmap).sort_index(), from_value_date, to_value_date)
ts = pd.Series(vvmap).sort_index().loc[from_value_date:to_value_date]
ts.name = seriename
return ts
......
......@@ -90,16 +90,6 @@ def closed_overlaps(fromdate, todate):
)
def subset(ts, fromdate, todate):
if fromdate is None and todate is None:
return ts
if isinstance(fromdate, tuple):
fromdate = fromdate[0]
if isinstance(todate, tuple):
todate = todate[0]
return ts.loc[fromdate:todate]
def inject_in_index(serie, revdate):
mindex = [(revdate, valuestamp) for valuestamp in serie.index]
serie.index = pd.MultiIndex.from_tuples(mindex, names=[
......
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