Skip to content

to_json doesn't work with Datetime.date #30904

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
WillAyd opened this issue Jan 10, 2020 · 0 comments · Fixed by #30977
Closed

to_json doesn't work with Datetime.date #30904

WillAyd opened this issue Jan 10, 2020 · 0 comments · Fixed by #30977
Labels
IO JSON read_json, to_json, json_normalize Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@WillAyd
Copy link
Member

WillAyd commented Jan 10, 2020

This is a regression between 0.25.3 and 1.0

>>> import pandas as pd
>>> import datetime
>>> data = [datetime.date(year=2020, month=1, day=1), "a"]
>>> pd.Series(data).to_json(date_format="iso")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/clones/pandas/pandas/core/generic.py", line 2363, in to_json
    indent=indent,
  File "/Users/williamayd/clones/pandas/pandas/io/json/_json.py", line 85, in to_json
    indent=indent,
  File "/Users/williamayd/clones/pandas/pandas/io/json/_json.py", line 145, in write
    self.indent,
  File "/Users/williamayd/clones/pandas/pandas/io/json/_json.py", line 199, in _write
    indent,
  File "/Users/williamayd/clones/pandas/pandas/io/json/_json.py", line 167, in _write
    indent=indent,
TypeError: Expected datetime object

Noticed while working on #30903

@WillAyd WillAyd added IO JSON read_json, to_json, json_normalize Regression Functionality that used to work in a prior pandas version labels Jan 10, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.0.0 milestone Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants