Skip to content

Commit

Permalink
BUG: join_non_unique doesn't sort properly for DatetimeIndex #2196
Browse files Browse the repository at this point in the history
  • Loading branch information
changhiskhan authored and wesm committed Nov 9, 2012
1 parent 2a22b5b commit cb1133f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,13 @@ def is_integer_dtype(arr_or_dtype):
(issubclass(tipo, np.datetime64) or
issubclass(tipo, np.timedelta64)))

def _is_int_or_datetime_dtype(arr_or_dtype):
# also timedelta64
if isinstance(arr_or_dtype, np.dtype):
tipo = arr_or_dtype.type
else:
tipo = arr_or_dtype.dtype.type
return issubclass(tipo, np.integer)

def is_datetime64_dtype(arr_or_dtype):
if isinstance(arr_or_dtype, np.dtype):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tools/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def _right_outer_join(x, y, max_groups):


def _factorize_keys(lk, rk, sort=True):
if com.is_integer_dtype(lk) and com.is_integer_dtype(rk):
if com._is_int_or_datetime_dtype(lk) and com._is_int_or_datetime_dtype(rk):
klass = lib.Int64Factorizer
lk = com._ensure_int64(lk)
rk = com._ensure_int64(rk)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,14 @@ def _check_join(left, right, how='inner'):
_check_join(index[:15], obj_index[5:], how='right')
_check_join(index[:15], obj_index[5:], how='left')

def test_join_nonunique(self):
idx1 = to_datetime(['2012-11-06 16:00:11.477563',
'2012-11-06 16:00:11.477563'])
idx2 = to_datetime(['2012-11-06 15:11:09.006507',
'2012-11-06 15:11:09.006507'])
rs = idx1.join(idx2, how='outer')
self.assert_(rs.is_monotonic)

def test_unpickle_daterange(self):
pth, _ = os.path.split(os.path.abspath(__file__))
filepath = os.path.join(pth, 'data', 'daterange_073.pickle')
Expand Down

0 comments on commit cb1133f

Please sign in to comment.