Skip to content

Commit dd4eb99

Browse files
committed
Merge pull request #5187 from jreback/dup_ops
BUG: Allow duplicate indices when performing operations that align (GH5185)
2 parents 38b717d + 159d1b7 commit dd4eb99

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ Bug Fixes
586586
context manager.
587587
- Fixed segfault on ``isnull(MultiIndex)`` (now raises an error instead)
588588
(:issue:`5123`, :issue:`5125`)
589+
- Allow duplicate indices when performing operations that align (:issue:`5185`)
589590

590591
pandas 0.12.0
591592
-------------

pandas/core/generic.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2455,10 +2455,12 @@ def _align_frame(self, other, join='outer', axis=None, level=None,
24552455

24562456
left = self._reindex_with_indexers({0: [join_index, ilidx],
24572457
1: [join_columns, clidx]},
2458-
copy=copy, fill_value=fill_value)
2458+
copy=copy, fill_value=fill_value,
2459+
allow_dups=True)
24592460
right = other._reindex_with_indexers({0: [join_index, iridx],
24602461
1: [join_columns, cridx]},
2461-
copy=copy, fill_value=fill_value)
2462+
copy=copy, fill_value=fill_value,
2463+
allow_dups=True)
24622464

24632465
if method is not None:
24642466
left = left.fillna(axis=fill_axis, method=method, limit=limit)

pandas/sparse/frame.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ def _reindex_columns(self, columns, copy, level, fill_value, limit=None,
572572
return SparseDataFrame(sdict, index=self.index, columns=columns,
573573
default_fill_value=self._default_fill_value)
574574

575-
def _reindex_with_indexers(self, reindexers, method=None, fill_value=None, limit=None, copy=False):
575+
def _reindex_with_indexers(self, reindexers, method=None, fill_value=None, limit=None,
576+
copy=False, allow_dups=False):
576577

577578
if method is not None or limit is not None:
578579
raise NotImplementedError("cannot reindex with a method or limit with sparse")

pandas/tests/test_frame.py

+8
Original file line numberDiff line numberDiff line change
@@ -3209,6 +3209,14 @@ def check(result, expected=None):
32093209
df = DataFrame(np.arange(12).reshape(3,4), columns=dups,dtype='float64')
32103210
self.assertRaises(ValueError, lambda : df[df.A > 6])
32113211

3212+
# dup aligining operations should work
3213+
# GH 5185
3214+
df1 = DataFrame([1, 2, 3, 4, 5], index=[1, 2, 1, 2, 3])
3215+
df2 = DataFrame([1, 2, 3], index=[1, 2, 3])
3216+
expected = DataFrame([0,2,0,2,2],index=[1,1,2,2,3])
3217+
result = df1.sub(df2)
3218+
assert_frame_equal(result,expected)
3219+
32123220
def test_insert_benchmark(self):
32133221
# from the vb_suite/frame_methods/frame_insert_columns
32143222
N = 10

0 commit comments

Comments
 (0)