From fbbbd40195803d95fb4f2a2d704f3a93118c8342 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Thu, 5 Jan 2017 12:24:13 +0000 Subject: stats/grammar: Raise helpful error when asked to parse absent events If you use the Parser to access events that Trappy understands, but that are not present in the trace, you currently get an inscrutable exception when trying to access `.loc[ self._window[0]:]` on the empty DataFrame in _get_data_frame. Ideally attempting to parse absent events would just return an empty DataFrame, but then we don't know what columns it should have. So instead let's just raise a more helpful error saying that the event is not present. --- trappy/stats/grammar.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'trappy/stats/grammar.py') diff --git a/trappy/stats/grammar.py b/trappy/stats/grammar.py index 05a6315..1f5820b 100644 --- a/trappy/stats/grammar.py +++ b/trappy/stats/grammar.py @@ -411,6 +411,9 @@ class Parser(object): """Pivot Data for concatenation""" data_frame = self._get_data_frame(cls) + if data_frame.empty: + raise ValueError("No events found for {}".format(cls.name)) + data_frame = handle_duplicate_index(data_frame) new_index = self._agg_df.index.union(data_frame.index) @@ -525,7 +528,9 @@ class Parser(object): data_frame = getattr(self.data, cls.name).data_frame - if self._window[1] is None: + if data_frame.empty: + return data_frame + elif self._window[1] is None: data_frame = data_frame.loc[self._window[0]:] else: data_frame = data_frame.loc[self._window[0]:self._window[1]] -- cgit v1.2.3