-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix bug in contains when looking up a string in a non-monotonic datet… #13574
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
Changes from 1 commit
f3b114f
cc0a188
2655dae
f11b9c1
ba82b51
f95576b
5701c69
3c202b1
713eaa6
675a6e3
1edc1df
2a96ab7
c989570
c2cc68d
2e8c993
5605f99
2f7fdd0
65849d3
8dbc0f4
93b7d13
dbd5330
7c357d2
27d2915
06103dd
7dd4091
20de266
44f3229
6f0a020
a711b42
084ceae
3f6d4bd
c9a27ed
05b976c
71a0675
0a70b5f
1bee56e
d7c028d
401b0ed
1a86b3a
3bf7cce
0f5a4e0
783ea6d
592a09d
690e034
d4348d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -721,6 +721,17 @@ def test_fillna_datetime64(self): | |
dtype=object) | ||
self.assert_index_equal(idx.fillna('x'), exp) | ||
|
||
def test_contains(self): | ||
#GH13572 | ||
dates = ['2015-01-03', '2015-01-01', '2015-01-04', '2015-01-05', '2015-01-02'] | ||
monotonic = pd.to_datetime(sorted(dates)) | ||
non_monotonic = pd.to_datetime(['2015-01-03', '2015-01-01', '2015-01-04', '2015-01-05', '2015-01-02']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can reuse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is NaT supposed to work with period indices? >>> pd.Period('NaT', freq='D') in pd.period_range('2015-01-01', periods=5, freq='D').insert(0, pd.NaT)
True Any of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx to confirm. Pls leave other nat-likes ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, TimedeltaIndices have a funny behavior as well. Checking for NaT-like objects always returns true >>> None in pd.to_timedelta(range(5), unit='d') + pd.offsets.Hour(1)
True Looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've taken out the timedelta issues as well, and created a new PR #13603. |
||
for idx in [non_monotonic, monotonic]: | ||
self.assertNotIn('2015-01-06', idx) | ||
self.assertNotIn(pd.Timestamp('2015-01-06'), idx) | ||
for dt in reversed(dates): | ||
self.assertIn(dt, idx) | ||
self.assertIn(pd.Timestamp(dt), idx) | ||
|
||
class TestPeriodIndex(DatetimeLike, tm.TestCase): | ||
_holder = PeriodIndex | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u also add tests for
TimedeltaIndex
andPeriodIndex
? (It looks work)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to just move this to the
Datetimelike
class which tests all datetimelike indexes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
further let's add testing with
Timestamp
anddatetime
as well (and a case where things are not there). finally add in aNaT
both in the contained index as well as a tests within