Skip to content

BUG: Allow duplicate indices when performing operations that align (GH5185) #5187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ Bug Fixes
context manager.
- Fixed segfault on ``isnull(MultiIndex)`` (now raises an error instead)
(:issue:`5123`, :issue:`5125`)
- Allow duplicate indices when performing operations that align (:issue:`5185`)

pandas 0.12.0
-------------
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2455,10 +2455,12 @@ def _align_frame(self, other, join='outer', axis=None, level=None,

left = self._reindex_with_indexers({0: [join_index, ilidx],
1: [join_columns, clidx]},
copy=copy, fill_value=fill_value)
copy=copy, fill_value=fill_value,
allow_dups=True)
right = other._reindex_with_indexers({0: [join_index, iridx],
1: [join_columns, cridx]},
copy=copy, fill_value=fill_value)
copy=copy, fill_value=fill_value,
allow_dups=True)

if method is not None:
left = left.fillna(axis=fill_axis, method=method, limit=limit)
Expand Down
3 changes: 2 additions & 1 deletion pandas/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ def _reindex_columns(self, columns, copy, level, fill_value, limit=None,
return SparseDataFrame(sdict, index=self.index, columns=columns,
default_fill_value=self._default_fill_value)

def _reindex_with_indexers(self, reindexers, method=None, fill_value=None, limit=None, copy=False):
def _reindex_with_indexers(self, reindexers, method=None, fill_value=None, limit=None,
copy=False, allow_dups=False):

if method is not None or limit is not None:
raise NotImplementedError("cannot reindex with a method or limit with sparse")
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3209,6 +3209,14 @@ def check(result, expected=None):
df = DataFrame(np.arange(12).reshape(3,4), columns=dups,dtype='float64')
self.assertRaises(ValueError, lambda : df[df.A > 6])

# dup aligining operations should work
# GH 5185
df1 = DataFrame([1, 2, 3, 4, 5], index=[1, 2, 1, 2, 3])
df2 = DataFrame([1, 2, 3], index=[1, 2, 3])
expected = DataFrame([0,2,0,2,2],index=[1,1,2,2,3])
result = df1.sub(df2)
assert_frame_equal(result,expected)

def test_insert_benchmark(self):
# from the vb_suite/frame_methods/frame_insert_columns
N = 10
Expand Down