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

get_delta: switch to pure-python handling

before:

DELTA all value dates 2.030127763748169
DELTA 1 day  0.20130324363708496

after:

DELTA all value dates 1.4739148616790771
DELTA 1 day  0.15337872505187988
parent e0a3e477cf7e
......@@ -222,44 +222,26 @@ class TimeSerie(SeriesServices):
def get_delta(self, cn, seriename, delta,
from_value_date=None,
to_value_date=None):
""" compute a series whose value dates are bounded to be
`delta` time after the insertion dates and where we
keep the most recent ones
"""
histo = self.get_history(
cn, seriename, deltabefore=-delta,
from_value_date=from_value_date,
to_value_date=to_value_date
)
for revdate, serie in histo.items():
inject_in_index(serie, revdate)
histo = pd.concat([serie for serie in histo.values()])
df = histo.reset_index()
# df_date is a dataframe with two columns: value_date and insertion_date
df_date = df.loc[:, ['insertion_date', 'value_date']]
# now in selected_dates each value_date has only one occurence
# which is the last inserted
selected_dates = df_date.groupby('value_date').max().reset_index()
ts = df[seriename]
# ts is built from the df returned from get_history
# ts index is now a simple index of tuples (insert_date, value_date)
ts.index = ((row.insertion_date, row.value_date)
for row in df.itertuples())
# in ts, there ie still all the couple value_date * insertion_date
# We now used the selected_dates to select in ts only
# the couple (value_date, insertion_date)
# which corresponds to the last insertion_date
ts_select = ts[[(row[2], row[1])
for row in selected_dates.itertuples()]]
# ts_select has still a simple index of tuples (value_date, insertion_date)
new_index = (elt[1] for elt in ts_select.index)
# we only keep the value_date information from the index
ts_select.index = new_index
return subset(ts_select, from_value_date, to_value_date)
vimap = {}
vvmap = {}
for idate, series in histo.items():
for vdate, value in series.iteritems():
if vdate not in vimap or vimap[vdate] < idate:
vimap[vdate] = idate
vvmap[vdate] = value
return subset(pd.Series(vvmap), from_value_date, to_value_date)
def exists(self, cn, seriename):
return self._get_ts_table(cn, seriename) is not 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