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

DEPR: 'epoch' date format in to_json #57987

Merged
merged 12 commits into from
Apr 19, 2024

Conversation

Aloqeely
Copy link
Member

doc/source/whatsnew/v2.2.2.rst Outdated Show resolved Hide resolved
@WillAyd
Copy link
Member

WillAyd commented Mar 25, 2024

Thanks for taking a look at this!

@WillAyd WillAyd added IO JSON read_json, to_json, json_normalize Deprecate Functionality to remove in pandas labels Mar 25, 2024
pandas/core/generic.py Outdated Show resolved Hide resolved
@@ -2530,6 +2535,14 @@ def to_json(
date_format = "iso"
elif date_format is None:
Copy link
Member

Choose a reason for hiding this comment

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

I think need to warn for anything that is not currently iso, including when date_format is None (although the message will be different)

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a warning for the date_format=None case that previously defaulted to "epoch"; this should in the future default to "iso"

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the to_json use cases don't involve dates and wouldn't be affected by the date_format value, throwing a warning in these cases might be unnecessary, essentially they will need to pass date_format='iso' for no reason to silence this warning, are you sure we should do this?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry to be more specific we need to warn when date_format=None and we actually serialize timestamp types. I agree no point in warning if a DataFrame has no timestamp type, but if users are relying on the default epoch behavior they need to be warned of the change

Copy link
Member

Choose a reason for hiding this comment

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

@WillAyd curious how would users get the old behavior? It would be good to add that in the warning message

Copy link
Member

Choose a reason for hiding this comment

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

The old behavior as in just an integer? I think the problem with that is it was an implementation detail of pandas spilling out into the JSON serializer. Historically our timestamps were exclusively nanoseconds since the Unix epoch, but with all the work @jbrockmendel has been doing that is no longer true (and _usually not true).

Copy link
Member

Choose a reason for hiding this comment

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

The old behavior as in just an integer?

Yeah. Just checking if we can still offer a suggestion for a migration path if they want to keep the old behavior

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so. Especially with our auto-inferencing of resolutions I don't see how it would be usable at all roundtripping through JSON

Copy link
Member

Choose a reason for hiding this comment

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

OK sounds good

doc/source/whatsnew/v2.2.2.rst Outdated Show resolved Hide resolved
@@ -2530,6 +2535,14 @@ def to_json(
date_format = "iso"
elif date_format is None:
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a warning for the date_format=None case that previously defaulted to "epoch"; this should in the future default to "iso"

@Aloqeely Aloqeely requested a review from WillAyd April 8, 2024 22:13
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Generally looks nice. Can you also add a test that is parametrized by DataFrames that may or may not have datetimelike values? In the case the DataFrame does not we want to assert no warning is raised

pandas/core/generic.py Outdated Show resolved Hide resolved
pandas/tests/io/json/test_pandas.py Outdated Show resolved Hide resolved
pandas/tests/io/json/test_pandas.py Outdated Show resolved Hide resolved
@Aloqeely

This comment has been minimized.

@Aloqeely Aloqeely requested a review from WillAyd April 16, 2024 05:06
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Looking good

pandas/core/generic.py Outdated Show resolved Hide resolved
doc/source/user_guide/io.rst Outdated Show resolved Hide resolved
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

@mroeschke any thoughts?

doc/source/whatsnew/v3.0.0.rst Outdated Show resolved Hide resolved
pandas/tests/io/json/test_pandas.py Outdated Show resolved Hide resolved
pandas/core/generic.py Outdated Show resolved Hide resolved
@WillAyd WillAyd merged commit 85cc67f into pandas-dev:main Apr 19, 2024
46 checks passed
@WillAyd
Copy link
Member

WillAyd commented Apr 19, 2024

Thanks @Aloqeely

pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DEP: Deprecate date_format="epoch" in to_json
4 participants