Skip to content

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

Merged
merged 1 commit into from
Dec 15, 2022

Conversation

MarcoGorelli
Copy link
Member

Comment on lines +192 to +196
elif (
(is_integer_object(val) or is_float_object(val))
and (val != val or val == NPY_NAT)
):
iresult[i] = NPY_NAT
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matches

elif is_integer_object(val) or is_float_object(val):
if val != val or val == NPY_NAT:
iresult[i] = NPY_NAT

@MarcoGorelli MarcoGorelli added Regression Functionality that used to work in a prior pandas version Datetime Datetime data dtype labels Dec 13, 2022
expected = Series(
[Timestamp("19801201"), Timestamp("19801201")] + [Timestamp("19810101")] * 5
)
expected[2] = np.nan
Copy link
Member

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)?

Copy link
Member Author

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:

elif checknull_with_nat_and_na(val):
iresult[i] = NPY_NAT
continue

, which is covered by a bunch of tests, e.g.

@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)

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MarcoGorelli MarcoGorelli added this to the 1.5.3 milestone Dec 14, 2022
@MarcoGorelli MarcoGorelli merged commit a5cbd1e into pandas-dev:main Dec 15, 2022
@lumberbot-app
Copy link

lumberbot-app bot commented Dec 15, 2022

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 1.5.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 a5cbd1e52e9078637c899167f40a29b4bc8901b9
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #50238:  REGR: to_datetime with non-ISO format, float, and nan fails on main'
  1. Push to a named branch:
git push YOURFORK 1.5.x:auto-backport-of-pr-50238-on-1.5.x
  1. Create a PR against branch 1.5.x, I would have named this PR:

"Backport PR #50238 on branch 1.5.x ( REGR: to_datetime with non-ISO format, float, and nan fails on main)"

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 Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REGR: to_datetime with non-ISO format, float, and nan fails on main
2 participants