-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,11 +125,14 @@ class FulldatetimeDict(YearMonthDayDict, total=False): | |
# --------------------------------------------------------------------- | ||
|
||
|
||
def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False): | ||
# Try to guess the format based on the first non-NaN element | ||
def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str | None: | ||
# Try to guess the format based on the first non-NaN element, return None if can't | ||
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 commentThe 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 commentThe 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 |
||
# GH#32264 np.str_ object | ||
return guess_datetime_format(first_non_nan_element, dayfirst=dayfirst) | ||
return None | ||
|
||
|
||
def should_cache( | ||
|
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