When we have a datetime64 column and writing to JSON, we get a warning about the default "epoch" date_format being deprecated.
However, when the datetime64 data is in the index, we don't get the warning, while we also get epoch values:
>>> df = pd.DataFrame({'A': [1, 2], 'B': [pd.Timestamp("2012-01-01"), pd.Timestamp("2012-01-02")]})
>>> df.to_json()
Pandas4Warning: The default 'epoch' date format is deprecated and will be removed in a future version, please use 'iso' date format instead.
'{"A":{"0":1,"1":2},"B":{"0":1325376000000,"1":1325462400000}}'
>>> df.set_index("B").to_json() # <-- no warning
'{"A":{"1325376000000":1,"1325462400000":2}}'
Both cases work fine with date_format="iso":
>>> df.to_json(date_format="iso")
'{"A":{"0":1,"1":2},"B":{"0":"2012-01-01T00:00:00.000","1":"2012-01-02T00:00:00.000"}}'
>>> df.set_index("B").to_json(date_format="iso")
'{"A":{"2012-01-01T00:00:00.000":1,"2012-01-02T00:00:00.000":2}}'
But so if we want to be able to change to "iso" by default in 4.0 for both cases, we also have to warn now in both cases
When we have a datetime64 column and writing to JSON, we get a warning about the default "epoch"
date_formatbeing deprecated.However, when the datetime64 data is in the index, we don't get the warning, while we also get epoch values:
Both cases work fine with
date_format="iso":But so if we want to be able to change to
"iso"by default in 4.0 for both cases, we also have to warn now in both cases