BUG: Cast a key to NaT before get loc from Index by yui-knk · Pull Request #13687 · pandas-dev/pandas (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation17 Commits1 Checks0 Files changed
Conversation
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
[ Show hidden characters]({{ revealButtonHref }})
@@ -697,6 +697,10 @@ def get_loc(self, key, method=None, tolerance=None): |
---|
------- |
loc : int |
""" |
if tslib.checknull_with_nat(key): |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use pd.isnull
Current coverage is 84.38%
@@ master #13687 diff @@
Files 142 142
Lines 51223 51225 +2
Methods 0 0
Messages 0 0
Branches 0 0
- Hits 43224 43226 +2
Misses 7999 7999
Partials 0 0
Powered by Codecov. Last updated by 6b9cd15...0960395
td = to_timedelta([pd.NaT]) |
---|
for v in [pd.NaT, None, float('nan'), np.nan]: |
self.assertTrue((v in td)) |
def test_construction(self): |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added!
I think related issues should be fixed by changing pd.Timedelta
to return pd.NaT
for these nat-likes (also _is_convertible_to_td
should include nat-likes).
# OK
pd.Timestamp(np.nan)
# NaT
pd.Period(np.nan)
# NaT
pd.Timedelta(np.nan)
# NaT
# NG, Timedelta should return pd.NaT
pd.Timestamp(None)
# NaT
pd.Period(None)
# NaT
pd.Timedelta(None)
# ValueError: cannot construct a Timedelta without a value/unit or descriptive keywords (days,seconds....)
I will challenge pd.Timedelta
issue on another PR :)
ok, pls add a whatsnew entry, otherwise lgtm.
Updated a whatsnew entry!
pd.NaT, None, float('nan') and np.nan are converted NaT in TestTimedeltas. So we should convert keys if keys are these value.
Fix pandas-dev#13603