Skip to content

Timedelta to_json with date_format='iso' #15137

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

Closed
TomAugspurger opened this issue Jan 15, 2017 · 7 comments
Closed

Timedelta to_json with date_format='iso' #15137

TomAugspurger opened this issue Jan 15, 2017 · 7 comments
Labels
Bug Enhancement IO JSON read_json, to_json, json_normalize Timedelta Timedelta data type

Comments

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jan 15, 2017

Is this formatting for timdelta columns intended / correct?

In [12]: df = pd.DataFrame({"A": pd.date_range("2016", periods=4, freq='D'),
    ...:                    "B": pd.timedelta_range('1D', periods=4, freq='D')})

In [13]: df.to_json(date_format='iso')
Out[13]: '{"A":{"0":"2016-01-01T00:00:00.000Z","1":"2016-01-02T00:00:00.000Z","2":"2016-01-03T00:00:00.000Z","3":"2016-01-04T00:00:00.000Z"},"B":{"0":"1970-01-02T00:00:00.000Z","1":"1970-01-03T00:00:00.000Z","2":"1970-01-04T00:00:00.000Z","3":"1970-01-05T00:00:00.000Z"}}'

So a pd.Timedelta('1D') goes to "1970-01-02T00:00:00.000Z".

The expected might be a duration like

"P1DT0H0M0S".

It seems to be reusing the logic for datetime columns and treating it as the equivalent int -> iso format. Ideally to_json will have a new paramater timedelta_format that takes the same values as date_format.

@TomAugspurger TomAugspurger added IO JSON read_json, to_json, json_normalize Timedelta Timedelta data type labels Jan 15, 2017
@TomAugspurger
Copy link
Contributor Author

xref #15136 and #14904

I can work on this, if we determine that it should be changed.

@jreback
Copy link
Contributor

jreback commented Jan 15, 2017

yes this is probably unsupported you can pass a default_handler to deal with it, though prob better do it in the c-code.

@TomAugspurger
Copy link
Contributor Author

I'm gonna attempt to do it in objToJSON.c, we'll see how that goes 😆

@TomAugspurger TomAugspurger added this to the 0.20.0 milestone Jan 15, 2017
@jreback
Copy link
Contributor

jreback commented Jan 15, 2017

yeah looks like its the iso code :>

@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
@ron819
Copy link

ron819 commented Dec 10, 2018

@TomAugspurger any progress with this?

@jreback
Copy link
Contributor

jreback commented Dec 10, 2018

@ron819 why don’t you do a pull request for this? we have thousands of issues and very few core devs, who mostly do code review

@mroeschke
Copy link
Member

Looks like this is solved on master by by: #30903

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Enhancement IO JSON read_json, to_json, json_normalize Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

4 participants