Skip to content

Commit e1aaf8c

Browse files
committed
Merge pull request #9525 from shoyer/ischwabacher-patch-3
Squashed version of #9515.
2 parents a064c7d + 44d6d2b commit e1aaf8c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

doc/source/whatsnew/v0.16.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ Bug Fixes
293293
- Bug in ``DataFrame.where`` and ``Series.where`` coerce numerics to string incorrectly (:issue:`9280`)
294294
- Bug in ``DataFrame.where`` and ``Series.where`` raise ``ValueError`` when string list-like is passed. (:issue:`9280`)
295295
- Accessing ``Series.str`` methods on with non-string values now raises ``TypeError`` instead of producing incorrect results (:issue:`9184`)
296-
296+
- Bug in ``DatetimeIndex.__contains__`` when index has duplicates and is not monotonic increasing (:issue:`9512`)
297297
- Fixed division by zero error for ``Series.kurt()`` when all values are equal (:issue:`9197`)
298298

299299

pandas/tseries/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _format_with_header(self, header, **kwargs):
6565
def __contains__(self, key):
6666
try:
6767
res = self.get_loc(key)
68-
return np.isscalar(res) or type(res) == slice
68+
return np.isscalar(res) or type(res) == slice or np.any(res)
6969
except (KeyError, TypeError):
7070
return False
7171

pandas/tseries/tests/test_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ def test_value_counts_unique(self):
292292

293293
tm.assert_index_equal(idx.unique(), exp_idx)
294294

295+
def test_nonunique_contains(self):
296+
# GH 9512
297+
for idx in map(DatetimeIndex, ([0, 1, 0], [0, 0, -1], [0, -1, -1],
298+
['2015', '2015', '2016'], ['2015', '2015', '2014'])):
299+
tm.assertIn(idx[0], idx)
300+
295301

296302
class TestTimedeltaIndexOps(Ops):
297303

@@ -684,6 +690,14 @@ def test_value_counts_unique(self):
684690

685691
tm.assert_index_equal(idx.unique(), exp_idx)
686692

693+
def test_nonunique_contains(self):
694+
# GH 9512
695+
for idx in map(TimedeltaIndex, ([0, 1, 0], [0, 0, -1], [0, -1, -1],
696+
['00:01:00', '00:01:00', '00:02:00'],
697+
['00:01:00', '00:01:00', '00:00:01'])):
698+
tm.assertIn(idx[0], idx)
699+
700+
687701
class TestPeriodIndexOps(Ops):
688702

689703
def setUp(self):

0 commit comments

Comments
 (0)