Skip to content

BUG: join_non_unique doesn't sort properly for DatetimeIndex #2196 #2197

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

Closed
wants to merge 1 commit into from
Closed
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
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