-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Cast a key to NaT before get loc from Index #13687
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,25 @@ class TestTimedeltas(tm.TestCase): | |
def setUp(self): | ||
pass | ||
|
||
def test_get_loc_nat(self): | ||
tidx = TimedeltaIndex(['1 days 01:00:00', 'NaT', '2 days 01:00:00']) | ||
|
||
self.assertEqual(tidx.get_loc(pd.NaT), 1) | ||
self.assertEqual(tidx.get_loc(None), 1) | ||
self.assertEqual(tidx.get_loc(float('nan')), 1) | ||
self.assertEqual(tidx.get_loc(np.nan), 1) | ||
|
||
def test_contains(self): | ||
# Checking for any NaT-like objects | ||
# GH 13603 | ||
td = to_timedelta(range(5), unit='d') + pd.offsets.Hour(1) | ||
for v in [pd.NaT, None, float('nan'), np.nan]: | ||
self.assertFalse((v in td)) | ||
|
||
td = to_timedelta([pd.NaT]) | ||
for v in [pd.NaT, None, float('nan'), np.nan]: | ||
self.assertTrue((v in td)) | ||
|
||
def test_construction(self): | ||
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. can u also add tests for 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 added! |
||
|
||
expected = np.timedelta64(10, 'D').astype('m8[ns]').view('i8') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
iNaT is an integer already
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.
We cast a key to NaT. And NaT is not an integer.
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.
see my other comment
use isnull and don't change internal cython code that should is not relevant
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.
iNaT IS by definition an integer
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 we don't use lib.is_integer ever directly
import from pandas.types.common (as it is)
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.
Thanks for your reviews.
I updated to use
isnull
and do not change on cython codeshttps://github.com/pydata/pandas/pull/13687/files#diff-c03d3accabc2e2f441d87b961f4425d7R701
I use
lib.is_integer
only ipython, this PR does not uselib.is_integer
, sorry to confuse you.Sure. But this PR converts a key to
NaT
(notiNaT
) which may not be integer, so we need to check key istslib.NaT
or not.