Skip to content

Commit cb1133f

Browse files
changhiskhanwesm
authored andcommitted
BUG: join_non_unique doesn't sort properly for DatetimeIndex #2196
1 parent 2a22b5b commit cb1133f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

pandas/core/common.py

+7
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,13 @@ def is_integer_dtype(arr_or_dtype):
852852
(issubclass(tipo, np.datetime64) or
853853
issubclass(tipo, np.timedelta64)))
854854

855+
def _is_int_or_datetime_dtype(arr_or_dtype):
856+
# also timedelta64
857+
if isinstance(arr_or_dtype, np.dtype):
858+
tipo = arr_or_dtype.type
859+
else:
860+
tipo = arr_or_dtype.dtype.type
861+
return issubclass(tipo, np.integer)
855862

856863
def is_datetime64_dtype(arr_or_dtype):
857864
if isinstance(arr_or_dtype, np.dtype):

pandas/tools/merge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def _right_outer_join(x, y, max_groups):
555555

556556

557557
def _factorize_keys(lk, rk, sort=True):
558-
if com.is_integer_dtype(lk) and com.is_integer_dtype(rk):
558+
if com._is_int_or_datetime_dtype(lk) and com._is_int_or_datetime_dtype(rk):
559559
klass = lib.Int64Factorizer
560560
lk = com._ensure_int64(lk)
561561
rk = com._ensure_int64(rk)

pandas/tseries/tests/test_timeseries.py

+8
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,14 @@ def _check_join(left, right, how='inner'):
16451645
_check_join(index[:15], obj_index[5:], how='right')
16461646
_check_join(index[:15], obj_index[5:], how='left')
16471647

1648+
def test_join_nonunique(self):
1649+
idx1 = to_datetime(['2012-11-06 16:00:11.477563',
1650+
'2012-11-06 16:00:11.477563'])
1651+
idx2 = to_datetime(['2012-11-06 15:11:09.006507',
1652+
'2012-11-06 15:11:09.006507'])
1653+
rs = idx1.join(idx2, how='outer')
1654+
self.assert_(rs.is_monotonic)
1655+
16481656
def test_unpickle_daterange(self):
16491657
pth, _ = os.path.split(os.path.abspath(__file__))
16501658
filepath = os.path.join(pth, 'data', 'daterange_073.pickle')

0 commit comments

Comments
 (0)