Skip to content

DEPR: casting strings to float in to_datetime with unit#50909

Merged
MarcoGorelli merged 2 commits into
pandas-dev:mainfrom
jbrockmendel:depr-unit-behavior
Jan 26, 2023
Merged

DEPR: casting strings to float in to_datetime with unit#50909
MarcoGorelli merged 2 commits into
pandas-dev:mainfrom
jbrockmendel:depr-unit-behavior

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

@mroeschke mroeschke added the Deprecate Functionality to remove in pandas label Jan 23, 2023

@mroeschke mroeschke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this is okay (+0) although it makes to_datetime a little less convenient.

@MarcoGorelli MarcoGorelli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me

Reckon the "inverse" should be deprecated as well, i.e. parsing numeric with format as strings, like

In [3]: to_datetime([20200101], format='%Y%m%d')
Out[3]: DatetimeIndex(['2020-01-01'], dtype='datetime64[ns]', freq=None)

?

Comment thread pandas/io/json/_json.py
Comment on lines +1216 to +1218
except OverflowError:
return data, False
except (TypeError, ValueError):

@MarcoGorelli MarcoGorelli Jan 24, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this just to avoid hitting the warning later in to_datetime(new_data, errors="raise", unit=date_unit), which would be outofbounds anyway?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

correct

@jbrockmendel

Copy link
Copy Markdown
Member Author

Reckon the "inverse" should be deprecated as well, i.e. parsing numeric with format as strings, like

That definitely seems like a potential footgun, no idea how common that is in the wild.

@MarcoGorelli MarcoGorelli added the Datetime Datetime data dtype label Jan 26, 2023
@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Jan 26, 2023
@MarcoGorelli MarcoGorelli merged commit 8448d39 into pandas-dev:main Jan 26, 2023
@jbrockmendel jbrockmendel deleted the depr-unit-behavior branch January 26, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Datetime Datetime data dtype Deprecate Functionality to remove in pandas

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: to_datetime with unit changes how strings are interpreted

3 participants