Skip to content

Commit 0a13bdb

Browse files
committed
add join to test to common and fix breaks for timedeltas and non-unique categorical indices.
1 parent b50df63 commit 0a13bdb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,7 @@ def _join_non_unique(self, other, how='left', return_indexers=False):
31263126
left_idx = _ensure_platform_int(left_idx)
31273127
right_idx = _ensure_platform_int(right_idx)
31283128

3129-
join_index = self.values.take(left_idx)
3129+
join_index = np.asarray(self.values.take(left_idx))
31303130
mask = left_idx == -1
31313131
np.putmask(join_index, mask, other._values.take(right_idx))
31323132

pandas/core/indexes/timedeltas.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ def union(self, other):
516516
result.freq = to_offset(result.inferred_freq)
517517
return result
518518

519-
def join(self, other, how='left', level=None, return_indexers=False):
519+
def join(self, other, how='left', level=None, return_indexers=False,
520+
sort=False):
520521
"""
521522
See Index.join
522523
"""
@@ -527,7 +528,8 @@ def join(self, other, how='left', level=None, return_indexers=False):
527528
pass
528529

529530
return Index.join(self, other, how=how, level=level,
530-
return_indexers=return_indexers)
531+
return_indexers=return_indexers,
532+
sort=sort)
531533

532534
def _wrap_joined_index(self, joined, other):
533535
name = self.name if self.name == other.name else None

pandas/tests/indexes/common.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def test_fillna(self):
905905

906906
def test_nulls(self):
907907
# this is really a smoke test for the methods
908-
# as these are adequantely tested for function elsewhere
908+
# as these are adequately tested for function elsewhere
909909

910910
for name, index in self.indices.items():
911911
if len(index) == 0:
@@ -933,3 +933,14 @@ def test_empty(self):
933933
index = self.create_index()
934934
assert not index.empty
935935
assert index[:0].empty
936+
937+
@pytest.mark.parametrize('how', ['outer', 'inner', 'left', 'right'])
938+
def test_join_self(self, how):
939+
index = self.create_index()
940+
joined = index.join(index, how=how)
941+
942+
if index.is_unique:
943+
assert index is joined
944+
945+
else:
946+
assert isinstance(joined, type(index))

0 commit comments

Comments
 (0)