ER: unclear error message when reindexing with duplicate index · Issue #4746 · pandas-dev/pandas (original) (raw)
When trying to reindex with an index with duplicate values, I get the error message ValueError: Shape of passed values is (1, 20), indices imply (1, 10)
, while I expected somthing like Reindexing only valid with uniquely valued Index objects
I see this with both 0.12 and master.
In [2]: pd.version Out[2]: '0.12.0-274-gc472099'
In [3]: s = pd.DataFrame(np.random.randn(10), index=[1,2,3,4,5,1,2,3,4,5])
In [4]: s Out[4]: 0 1 -0.067753 2 -1.544545 3 0.726160 4 0.562298 5 -0.094550 1 0.753334 2 -0.893318 3 -0.275085 4 2.645206 5 -0.926170
In [5]: s.reindex(index=range(len(s)))
ValueError Traceback (most recent call last) in () ----> 1 s.reindex(index=range(len(s)))
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\generic.pyc in reindex(self, *args, **kwargs) 1085 1086 # perform the reindex on the axes -> 1087 return self._reindex_axes(axes, level, limit, method, fill_value, copy, takeable=takeable)._propogate_attributes(self) 1088 1089 def _reindex_axes(self, axes, level, limit, method, fill_value, copy, takeable=False):
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\frame.pyc in _reindex_axes(self, axes, level, limit, method, fill_value, copy, takeable) 2268 if index is not None: 2269 frame = frame._reindex_index(index, method, copy, level, -> 2270 fill_value, limit, takeable=takeable) 2271 2272 return frame
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\frame.pyc in _reindex_index(self, new_index, method, copy, level, fill_value, limit, takeable) 2278 takeable=takeable) 2279 return self._reindex_with_indexers({0: [new_index, indexer]}, -> 2280 copy=copy, fill_value=fill_value) 2281 2282 def _reindex_columns(self, new_columns, copy, level, fill_value=NA,
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\generic.pyc in _reindex_with_indexers(self, reindexers, method, fill_value, limit, copy) 1184 indexer = com._ensure_int64(indexer) 1185 new_data = new_data.reindex_indexer(index, indexer, axis=baxis, -> 1186 fill_value=fill_value) 1187 1188 elif baxis == 0 and index is not None and index is not new_data.axes[baxis]:
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.pyc in reindex_indexer(self, new_axis, indexer, axis, fill_value) 2673 new_axes = list(self.axes) 2674 new_axes[axis] = new_axis -> 2675 return self.class(new_blocks, new_axes) 2676 2677 def _reindex_indexer_items(self, new_items, indexer, fill_value):
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.pyc in init(self, blocks, axes, do_integrity_check, fastpath) 1563 1564 if do_integrity_check: -> 1565 self._verify_integrity() 1566 1567 self._has_sparse = False
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.pyc in _verify_integrity(self) 1826 if not block.is_sparse and block.values.shape[1:] != mgr_shape[1:]: 1827 construction_error( -> 1828 tot_items, block.values.shape[1:], self.axes) 1829 if len(self.items) != tot_items: 1830 raise AssertionError('Number of manager items must equal union of '
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.pyc in construction_error(tot_items, block_shape, axes) 3063 raise ValueError("Shape of passed values is %s, indices imply %s" % ( 3064 tuple(map(int, [tot_items] + list(block_shape))), -> 3065 tuple(map(int, [len(ax) for ax in axes])))) 3066 3067
ValueError: Shape of passed values is (1, 15), indices imply (1, 10)
In [6]: s.reindex(index=s.index.order())
ValueError Traceback (most recent call last) in () ----> 1 s.reindex(index=s.index.order())
.....
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.py in construction_error(tot_items, block_shape, axes) 3063 raise ValueError("Shape of passed values is %s, indices imply %s" % ( 3064 tuple(map(int, [tot_items] + list(block_shape))), -> 3065 tuple(map(int, [len(ax) for ax in axes])))) 3066 3067
ValueError: Shape of passed values is (1, 20), indices imply (1, 10)