From b28d7be9fc74ef410c3d2c6227f4475ef801d552 Mon Sep 17 00:00:00 2001 From: Qais Yousef Date: Thu, 11 Apr 2019 13:56:10 +0100 Subject: [PATCH] trace.py: improve add_events_deltas() Use the builtin diff() function in pandas to generate the deltas. diff() will return a NaN value for the first delta, we fill it with 0 in this case. Signed-off-by: Qais Yousef --- lisa/trace.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lisa/trace.py b/lisa/trace.py index a2f8d2486..b772a5079 100644 --- a/lisa/trace.py +++ b/lisa/trace.py @@ -91,10 +91,8 @@ class TraceBase(abc.ABC): if not inplace: df = df.copy() - df.loc[df.index[:-1], col_name] = df.index.values[1:] - df.index.values[:-1] - # Fix the last event, which will have a NaN duration - # Set duration to trace_end - last_event - df.loc[df.index[-1], col_name] = self.end - df.index[-1] + df[col_name] = df.index + df[col_name] = df[col_name].diff().fillna(0) return df -- GitLab