Closed
Description
Intertwined with #15137 though a slight different issue.
date_format="iso"
has different behavior for Timedeltas depending on whether or not the Timedelta is in a DTA or an object array. To illustrate:
# Wrong format ref 15137, but at least tries to do some formatting
>>> pd.DataFrame([[pd.Timedelta("1D")]]).to_json(date_format="iso")
'{"0":{"0":"1970-01-02T00:00:00.000Z"}}'
# Object array has no formatting
>>> pd.DataFrame([[pd.Timedelta("1D")]]).astype(object).to_json(date_format="iso")
'{"0":{"0":86400000}}'
By contrast the same issue does not appear with datetimes
>>> pd.DataFrame([[pd.Timestamp(1)]]).to_json(date_format="iso")
'{"0":{"0":"1970-01-01T00:00:00.000Z"}}'
# Below still formats as iso in spite of being object array
>>> pd.DataFrame([[pd.Timestamp(1)]]).astype(object).to_json(date_format="iso")
'{"0":{"0":"1970-01-01T00:00:00.000Z"}}'