-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REGR: to_datetime with non-ISO format, float, and nan fails on main #50238
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
Conversation
elif ( | ||
(is_integer_object(val) or is_float_object(val)) | ||
and (val != val or val == NPY_NAT) | ||
): | ||
iresult[i] = NPY_NAT |
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.
matches
Lines 343 to 346 in 6598797
elif is_integer_object(val) or is_float_object(val): | |
if val != val or val == NPY_NAT: | |
iresult[i] = NPY_NAT |
expected = Series( | ||
[Timestamp("19801201"), Timestamp("19801201")] + [Timestamp("19810101")] * 5 | ||
) | ||
expected[2] = np.nan |
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.
If np.nan
was pd.datetime64('NaT')
would this hit the elif
block added in this PR (and if so could you add a test for it)?
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.
hey - no, that would hit this branch:
pandas/pandas/_libs/tslibs/strptime.pyx
Lines 163 to 165 in e8e77c7
elif checknull_with_nat_and_na(val): | |
iresult[i] = NPY_NAT | |
continue |
, which is covered by a bunch of tests, e.g.
pandas/pandas/tests/tools/test_to_datetime.py
Lines 168 to 189 in e8e77c7
@pytest.mark.parametrize( | |
"input_s", | |
[ | |
# Null values with Strings | |
["19801222", "20010112", None], | |
["19801222", "20010112", np.nan], | |
["19801222", "20010112", NaT], | |
["19801222", "20010112", "NaT"], | |
# Null values with Integers | |
[19801222, 20010112, None], | |
[19801222, 20010112, np.nan], | |
[19801222, 20010112, NaT], | |
[19801222, 20010112, "NaT"], | |
], | |
) | |
def test_to_datetime_format_YYYYMMDD_with_none(self, input_s): | |
# GH 30011 | |
# format='%Y%m%d' | |
# with None | |
expected = Series([Timestamp("19801222"), Timestamp("20010112"), NaT]) | |
result = Series(to_datetime(input_s, format="%Y%m%d")) | |
tm.assert_series_equal(result, expected) |
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.
LGTM
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
…float, and nan fails on main
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.