Commit ce358550 authored by Arnaud Campeas's avatar Arnaud Campeas
Browse files

get_delta: fix issue with nans in the history

Previously, the nans where ignored when calling the series through the
get_delta method which causes discrepancies between the series
obtained from a standard get and a get_delta
parent 9fe6bc7d6327
......@@ -938,16 +938,14 @@ insertion_date value_date
2015-01-21 00:00:00+00:00 2.0
""", tsh.get(engine, 'with_na'))
# the last value should not be visible
# the last value is also correctly hidden
assert_df("""
2015-01-20 00:00:00+00:00 0.0
2015-01-21 00:00:00+00:00 1.0
2015-01-22 00:00:00+00:00 1.0
""", tsh.get_delta(engine, 'with_na', delta=timedelta(hours=0)))
# since the last nan inserted in the last revision is not
# displayed by get_history, the last value used in get delta is
# the one inserted in 2015-01-21 for the appdate 2015-01-22
# the value gathered by get_delta at value date 2015-01-22 is a
# nan, so it masks the previous ones at the same date
assert_hist("""
insertion_date value_date
2015-01-20 00:00:00+00:00 2015-01-20 00:00:00+00:00 0.0
......@@ -958,7 +956,8 @@ insertion_date value_date
2015-01-22 00:00:00+00:00 1.0
2015-01-22 00:00:00+00:00 2015-01-20 00:00:00+00:00 2.0
2015-01-21 00:00:00+00:00 2.0
""", tsh.get_history(engine, 'with_na'))
2015-01-22 00:00:00+00:00 NaN
""", tsh.get_history(engine, 'with_na', _keep_nans=True))
def test_nr_gethistory(engine, tsh):
......
......@@ -169,7 +169,8 @@ class TimeSerie(SeriesServices):
to_value_date=None,
deltabefore=None,
deltaafter=None,
diffmode=False):
diffmode=False,
_keep_nans=False):
table = self._get_ts_table(cn, seriename)
if table is None:
return
......@@ -240,7 +241,7 @@ class TimeSerie(SeriesServices):
series = diffs
else:
series = [
(idate, ts.dropna())
(idate, ts if _keep_nans else ts.dropna() )
for idate, ts in series
]
......@@ -259,7 +260,8 @@ class TimeSerie(SeriesServices):
histo = self.get_history(
cn, seriename, deltabefore=-delta,
from_value_date=from_value_date,
to_value_date=to_value_date
to_value_date=to_value_date,
_keep_nans=True
)
if histo is None:
return None
......@@ -274,7 +276,7 @@ class TimeSerie(SeriesServices):
ts = pd.Series(vvmap).sort_index().loc[from_value_date:to_value_date]
ts.name = seriename
return ts
return ts.dropna()
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