Skip to content

to_json doesn't work with Datetime.date #30904

Closed
@WillAyd

Description

@WillAyd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO JSONread_json, to_json, json_normalizeRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions