Skip to content
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

Merged

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Oct 6, 2022

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

Comment on lines -967 to -968
if not isinstance(dt_str, str):
return None
Copy link
Member Author

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

@MarcoGorelli MarcoGorelli added this to the 1.6 milestone Oct 6, 2022
@mroeschke mroeschke merged commit 32474d9 into pandas-dev:main Oct 6, 2022
@mroeschke
Copy link
Member

Thanks @MarcoGorelli (Finally have the walrus operator in the code base!)

@jbrockmendel
Copy link
Member

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:
Copy link
Member

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?

Copy link
Member Author

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

@mroeschke mroeschke modified the milestones: 1.6, 2.0 Oct 13, 2022
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
…nput (pandas-dev#48970)

* BUG: to_datetime(..., infer_datetime_format=True) fails with np.str_ input

* add return

Co-authored-by: MarcoGorelli <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: to_datetime(..., infer_datetime_format=True) fails if argument is np.str_
3 participants