-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_datetime(..., infer_datetime_format=True) fails with np.str_input #48970
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
BUG: to_datetime(..., infer_datetime_format=True) fails with np.str_input #48970
Conversation
if not isinstance(dt_str, str): | ||
return None |
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.
no longer necessary, as the input is typed as : str
22f68a5
to
20e1960
Compare
Thanks @MarcoGorelli (Finally have the walrus operator in the code base!) |
Wave of the future! |
non_nan_elements = notna(arr).nonzero()[0] | ||
if len(non_nan_elements): | ||
return guess_datetime_format(arr[non_nan_elements[0]], dayfirst=dayfirst) | ||
if type(first_non_nan_element := arr[non_nan_elements[0]]) is str: |
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.
is the fallback path for this less performant? could we instead cast np.str_ objs to str here?
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.
good call, have opened #48974 for now, will get back to it when I get a chance
…nput (pandas-dev#48970) * BUG: to_datetime(..., infer_datetime_format=True) fails with np.str_ input * add return Co-authored-by: MarcoGorelli <>
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.I haven't added a whatsnew note as this worked fine in the last released versions, it just fixes a regression introduced between releases so makes no difference to users
Same kind of thing as #45280