aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavi Merino <javi.merino@arm.com>2016-04-27 10:57:41 +0100
committerJavi Merino <javi.merino@arm.com>2016-04-28 14:53:27 +0100
commitaa4bece3adc7f37b8121c84f2515ab2300c132f9 (patch)
tree455e690aa7a10a8c7b3bcbd72b91f8d86f7bd2bb
parent90b588aeb958af7f6ccf587226958f2e6b8b81d1 (diff)
downloadtrappy-aa4bece3adc7f37b8121c84f2515ab2300c132f9.tar.gz
ILinePlot: don't call data_frame what's just a python dict
Since the dawn of time we have a "data_frame" variable in ILinePlot that is actually defined as a pd.Series() but it's acting as a dict. Rename it and turn the pd.Series into a dict, as it is simpler and it really is what this variable moves around.
-rw-r--r--tests/test_plotter.py4
-rw-r--r--trappy/plotter/ILinePlot.py30
-rw-r--r--trappy/plotter/ILinePlotGen.py8
3 files changed, 20 insertions, 22 deletions
diff --git a/tests/test_plotter.py b/tests/test_plotter.py
index 8a83a09..a2a17f5 100644
--- a/tests/test_plotter.py
+++ b/tests/test_plotter.py
@@ -269,9 +269,7 @@ class TestILinePlotter(unittest.TestCase):
dfr = pd.DataFrame([0, 1, 2, 3], columns=["a"])
iplot = trappy.ILinePlot(dfr, column=["a"])
- s = pd.Series()
- s["s1"] = s1
- s["s2"] = s2
+ s = {"s1": s1, "s2": s2}
merged = iplot._fix_indexes(s)
expected_index = index1 + index2
diff --git a/trappy/plotter/ILinePlot.py b/trappy/plotter/ILinePlot.py
index 5449746..84bcb55 100644
--- a/trappy/plotter/ILinePlot.py
+++ b/trappy/plotter/ILinePlot.py
@@ -187,7 +187,7 @@ class ILinePlot(AbstractDataPlotter):
self._layout = ILinePlotGen(len_pivots, **self._attr)
plot_index = 0
for p_val in pivot_vals:
- data_frame = pd.Series()
+ data_dict = {}
for constraint in self.c_mgr:
if permute:
trace_idx, pivot = p_val
@@ -200,7 +200,7 @@ class ILinePlot(AbstractDataPlotter):
result = constraint.result
if pivot in result:
- data_frame[legend] = result[pivot]
+ data_dict[legend] = result[pivot]
if permute:
title = self.traces[plot_index].name
@@ -210,8 +210,8 @@ class ILinePlot(AbstractDataPlotter):
title = ""
# Fix data frame indexes if necessary
- data_frame = self._fix_indexes(data_frame)
- self._layout.add_plot(plot_index, data_frame, title, test=test)
+ data_dict = self._fix_indexes(data_dict)
+ self._layout.add_plot(plot_index, data_dict, title, test=test)
plot_index += 1
self._layout.finish()
@@ -227,7 +227,7 @@ class ILinePlot(AbstractDataPlotter):
for constraint in self.c_mgr:
result = constraint.result
title = str(constraint)
- data_frame = pd.Series()
+ data_dict = {}
for pivot in pivot_vals:
if pivot in result:
@@ -236,27 +236,27 @@ class ILinePlot(AbstractDataPlotter):
else:
key = "{0}: {1}".format(self._attr["pivot"], self._attr["map_label"].get(pivot, pivot))
- data_frame[key] = result[pivot]
+ data_dict[key] = result[pivot]
# Fix data frame indexes if necessary
- data_frame = self._fix_indexes(data_frame)
- self._layout.add_plot(plot_index, data_frame, title)
+ data_dict = self._fix_indexes(data_dict)
+ self._layout.add_plot(plot_index, data_dict, title)
plot_index += 1
self._layout.finish()
- def _fix_indexes(self, data_frame):
+ def _fix_indexes(self, data_dict):
"""
In case of multiple traces with different indexes (i.e. x-axis values),
create new ones with same indexes
"""
# 1) Check if we are processing multiple traces
- if len(data_frame) > 1:
+ if len(data_dict) > 1:
# 2) Merge the data frames to obtain common indexes
- df_columns = list(data_frame.keys())
- dedup_data = [handle_duplicate_index(s) for s in data_frame.values]
- data_frame = pd.Series(dedup_data, index=df_columns)
- merged_df = pd.concat(data_frame.get_values(), axis=1)
+ df_columns = list(data_dict.keys())
+ dedup_data = [handle_duplicate_index(s) for s in data_dict.values()]
+ ret = pd.Series(dedup_data, index=df_columns)
+ merged_df = pd.concat(ret.get_values(), axis=1)
merged_df.columns = df_columns
# 3) Fill NaN values depending on drawstyle
if self._attr["drawstyle"] == "steps-post":
@@ -271,4 +271,4 @@ class ILinePlot(AbstractDataPlotter):
return merged_df
else:
- return data_frame
+ return data_dict
diff --git a/trappy/plotter/ILinePlotGen.py b/trappy/plotter/ILinePlotGen.py
index 13860de..9e3f3f8 100644
--- a/trappy/plotter/ILinePlotGen.py
+++ b/trappy/plotter/ILinePlotGen.py
@@ -182,14 +182,14 @@ class ILinePlotGen(object):
fig_params["pointSize"] = self._attr["point_size"]
- def add_plot(self, plot_num, data_frame, title="", test=False):
+ def add_plot(self, plot_num, data_dict, title="", test=False):
"""Add a plot for the corresponding index
:param plot_num: The linear index of the plot
:type plot_num: int
- :param data_frame: The data for the plot
- :type data_frame: :mod:`pandas.DataFrame`
+ :param data_dict: The data for the plot
+ :type data_dict: dict
:param title: The title for the plot
:type title: str
@@ -197,7 +197,7 @@ class ILinePlotGen(object):
fig_name = self._fig_map[plot_num]
fig_params = {}
- fig_params["data"] = json.loads(data_frame.to_json())
+ fig_params["data"] = dict((k, v.T.to_dict()) for k, v in data_dict.iteritems())
fig_params["name"] = fig_name
fig_params["rangesel"] = False
fig_params["logscale"] = False