Skip to content

ENH: Add new date_format option to_json matching datetime.isoformat exactly #47930

Open
@PMLP-novo

Description

@PMLP-novo

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish to have the option to serialised datetimes the same way in the same way that the build in datetime.isoformat serialises them. Such that I don't produce datetimes in different formats and my tests can be writen nices.
Right now:
pandas datetime produces: "2022-08-02T15:24:54.987Z"
compared to python datetime: "2022-08-02T15:24:54.987994"

Feature Description

I wish the following test would pass

import pandas as pd
from datetime import datetime
dt = datetime.now()
df = pd.DataFrame([{"test":dt}])
assert df.to_json(date_format="python-iso", orient="records")[0]["test"] == dt.isoformat()

Alternative Solutions

the new date_format option could have other names

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions