Skip to content

Commit 6f4af67

Browse files
committed
Merge pull request #8364 from jreback/datetime_ops
BUG: Bug in alignment with TimeOps and non-unique indexes (GH8363)
2 parents c8e88d4 + fcd1a94 commit 6f4af67

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

doc/source/v0.15.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ Bug Fixes
867867

868868
- Bug in ``tslib.tz_convert`` and ``tslib.tz_convert_single`` may return different results (:issue:`7798`)
869869
- Bug in ``DatetimeIndex.intersection`` of non-overlapping timestamps with tz raises ``IndexError`` (:issue:`7880`)
870-
870+
- Bug in alignment with TimeOps and non-unique indexes (:issue:`8363`)
871871

872872

873873
- Bug in ``GroupBy.filter()`` where fast path vs. slow path made the filter

pandas/core/generic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3112,9 +3112,13 @@ def _align_series(self, other, join='outer', axis=None, level=None,
31123112
raise ValueError('cannot align series to a series other than '
31133113
'axis 0')
31143114

3115-
join_index, lidx, ridx = self.index.join(other.index, how=join,
3116-
level=level,
3117-
return_indexers=True)
3115+
# equal
3116+
if self.index.equals(other.index):
3117+
join_index, lidx, ridx = None, None, None
3118+
else:
3119+
join_index, lidx, ridx = self.index.join(other.index, how=join,
3120+
level=level,
3121+
return_indexers=True)
31183122

31193123
left_result = self._reindex_indexer(join_index, lidx, copy)
31203124
right_result = other._reindex_indexer(join_index, ridx, copy)

pandas/tests/test_frame.py

+15
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,21 @@ def check(result, expected=None):
35233523
result = z.ix[['a', 'c', 'a']]
35243524
check(result,expected)
35253525

3526+
3527+
def test_column_dups_indexing2(self):
3528+
3529+
# GH 8363
3530+
# datetime ops with a non-unique index
3531+
df = DataFrame({'A' : np.arange(5), 'B' : np.arange(1,6)},index=[2,2,3,3,4])
3532+
result = df.B-df.A
3533+
expected = Series(1,index=[2,2,3,3,4])
3534+
assert_series_equal(result,expected)
3535+
3536+
df = DataFrame({'A' : date_range('20130101',periods=5), 'B' : date_range('20130101 09:00:00', periods=5)},index=[2,2,3,3,4])
3537+
result = df.B-df.A
3538+
expected = Series(Timedelta('9 hours'),index=[2,2,3,3,4])
3539+
assert_series_equal(result,expected)
3540+
35263541
def test_insert_benchmark(self):
35273542
# from the vb_suite/frame_methods/frame_insert_columns
35283543
N = 10

0 commit comments

Comments
 (0)