diff options
author | Javi Merino <javi.merino@arm.com> | 2016-03-09 18:39:31 +0000 |
---|---|---|
committer | Javi Merino <javi.merino@arm.com> | 2016-03-15 09:57:13 +0100 |
commit | fadc28a47e8695d0757a252a197c0a903bd5a830 (patch) | |
tree | d1440bcf4e8122b2c7aca292ff400505179b12de /tests | |
parent | f2666cb3e55dfc7812d6c170f992190e795602cf (diff) | |
download | trappy-fadc28a47e8695d0757a252a197c0a903bd5a830.tar.gz |
ILinePlot: fix merging with duplicate indexes in one of the dataframes
If one of the dataframes passed to ILinePlot have duplicate indexes,
view() fails with
File "/home/javi/src/trappy/trappy/tests/trappy/plotter/ILinePlot.py", line 151, in view
self._plot(self._attr["permute"], test)
File "/home/javi/src/trappy/trappy/tests/trappy/plotter/ILinePlot.py", line 199, in _plot
data_frame = self._fix_indexes(data_frame)
File "/home/javi/src/trappy/trappy/tests/trappy/plotter/ILinePlot.py", line 243, in _fix_indexes
merged_df = pd.concat(data_frame.get_values(), axis=1)
File "/usr/lib/python2.7/dist-packages/pandas/tools/merge.py", line 813, in concat
return op.get_result()
File "/usr/lib/python2.7/dist-packages/pandas/tools/merge.py", line 966, in get_result
tmpdf = DataFrame(data, index=index)
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 226, in __init__
mgr = self._init_dict(data, index, columns, dtype=dtype)
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 363, in _init_dict
dtype=dtype)
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 5163, in _arrays_to_mgr
arrays = _homogenize(arrays, index, dtype)
File "/usr/lib/python2.7/dist-packages/pandas/core/frame.py", line 5465, in _homogenize
v = v.reindex(index, copy=False)
File "/usr/lib/python2.7/dist-packages/pandas/core/series.py", line 2268, in reindex
return super(Series, self).reindex(index=index, **kwargs)
File "/usr/lib/python2.7/dist-packages/pandas/core/generic.py", line 1962, in reindex
method, fill_value, copy).__finalize__(self)
File "/usr/lib/python2.7/dist-packages/pandas/core/generic.py", line 1981, in _reindex_axes
fill_value=fill_value, copy=copy, allow_dups=False)
File "/usr/lib/python2.7/dist-packages/pandas/core/generic.py", line 2073, in _reindex_with_indexers
copy=copy)
File "/usr/lib/python2.7/dist-packages/pandas/core/internals.py", line 3503, in reindex_indexer
self.axes[axis]._can_reindex(indexer)
File "/usr/lib/python2.7/dist-packages/pandas/core/index.py", line 2086, in _can_reindex
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis
Fix it by filtering the DataFrames through handle_duplicate_index()
before merging them.
Change-Id: I34e6af523d14e35c3a17652924fbaa5989c1243d
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_plotter.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/test_plotter.py b/tests/test_plotter.py index f009a50..b374783 100644 --- a/tests/test_plotter.py +++ b/tests/test_plotter.py @@ -254,6 +254,12 @@ class TestILinePlotter(unittest.TestCase): trappy.ILinePlot([dfr1, dfr2], column=["a", "a"]).view(test=True) + def test_duplicate_merging(self): + dfr1 = pd.DataFrame([1, 2, 3, 4], index=[0., 0., 1., 2.], columns=["a"]) + dfr2 = pd.DataFrame([2, 3, 4, 5], index=[1., 1., 1., 2.], columns=["a"]) + + trappy.ILinePlot([dfr1, dfr2], column=["a", "a"]).view(test=True) + class TestBarPlot(unittest.TestCase): def setUp(self): self.dfr = pd.DataFrame({"foo": [1, 2, 3], |