Skip to content

Commit ce4ae93

Browse files
committed
BUG: fix MultiIndex segfault due to internal refactoring. close #1532
1 parent 6904dba commit ce4ae93

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

doc/source/v0.8.0.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ necessary. See the `full release notes
1414
<https://github.com/pydata/pandas/blob/master/RELEASE.rst>`__ or issue tracker
1515
on GitHub for a complete list.
1616

17-
TODO: contributor list
17+
Support for non-unique indexes
18+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
20+
All objects can now work with non-unique indexes. Data alignment / join
21+
operations work according to SQL join semantics (including, if application,
22+
index duplication in many-to-many joins)
1823

1924
NumPy datetime64 dtype and 1.6 dependency
2025
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -102,13 +107,6 @@ Time series changes and improvements
102107
using the frequency (if any) of the index, as opposed to a naive lead/lag
103108
using shift
104109

105-
Support for non-unique indexes
106-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107-
108-
All objects can now work with non-unique indexes. Data alignment / join
109-
operations work according to SQL join semantics (including, if application,
110-
index duplication in many-to-many joins)
111-
112110
Other new features
113111
~~~~~~~~~~~~~~~~~~
114112

pandas/core/index.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -976,35 +976,34 @@ def _join_monotonic(self, other, how='left', return_indexers=False):
976976
else:
977977
return ret_index
978978

979+
sv = self.values
980+
ov = other.values
981+
979982
if self.is_unique and other.is_unique:
980983
# We can perform much better than the general case
981984
if how == 'left':
982985
join_index = self
983986
lidx = None
984-
ridx = self._left_indexer_unique(self, other)
987+
ridx = self._left_indexer_unique(sv, ov)
985988
elif how == 'right':
986989
join_index = other
987-
lidx = self._left_indexer_unique(other, self)
990+
lidx = self._left_indexer_unique(ov, sv)
988991
ridx = None
989992
elif how == 'inner':
990-
join_index, lidx, ridx = self._inner_indexer(self.values,
991-
other.values)
993+
join_index, lidx, ridx = self._inner_indexer(sv,ov)
992994
join_index = self._wrap_joined_index(join_index, other)
993995
elif how == 'outer':
994-
join_index, lidx, ridx = self._outer_indexer(self.values,
995-
other.values)
996+
join_index, lidx, ridx = self._outer_indexer(sv, ov)
996997
join_index = self._wrap_joined_index(join_index, other)
997998
else:
998999
if how == 'left':
999-
join_index, lidx, ridx = self._left_indexer(self, other)
1000+
join_index, lidx, ridx = self._left_indexer(sv, ov)
10001001
elif how == 'right':
10011002
join_index, ridx, lidx = self._left_indexer(other, self)
10021003
elif how == 'inner':
1003-
join_index, lidx, ridx = self._inner_indexer(self.values,
1004-
other.values)
1004+
join_index, lidx, ridx = self._inner_indexer(sv, ov)
10051005
elif how == 'outer':
1006-
join_index, lidx, ridx = self._outer_indexer(self.values,
1007-
other.values)
1006+
join_index, lidx, ridx = self._outer_indexer(sv, ov)
10081007
join_index = self._wrap_joined_index(join_index, other)
10091008

10101009
if return_indexers:

pandas/tests/test_multilevel.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,16 @@ def test_dataframe_insert_column_all_na(self):
13841384
df['new'] = s
13851385
self.assert_(df['new'].isnull().all())
13861386

1387+
def test_join_segfault(self):
1388+
# 1532
1389+
df1 = DataFrame({'a': [1, 1], 'b': [1, 2], 'x': [1, 2]})
1390+
df2 = DataFrame({'a': [2, 2], 'b': [1, 2], 'y': [1, 2]})
1391+
df1 = df1.set_index(['a', 'b'])
1392+
df2 = df2.set_index(['a', 'b'])
1393+
# it works!
1394+
for how in ['left', 'right', 'outer']:
1395+
df1.join(df2, how=how)
1396+
13871397
if __name__ == '__main__':
13881398

13891399
# unittest.main()

0 commit comments

Comments
 (0)