@@ -822,7 +822,7 @@ def test_date_index_and_values(self, date_format, as_object, date_typ):
822
822
expected = '{"1577836800000":1577836800000,"null":null}'
823
823
else :
824
824
expected = (
825
- '{"2020-01-01T00:00:00.000Z ":"2020-01-01T00:00:00.000Z ","null":null}'
825
+ '{"2020-01-01T00:00:00.000 ":"2020-01-01T00:00:00.000 ","null":null}'
826
826
)
827
827
828
828
if as_object :
@@ -875,8 +875,6 @@ def test_date_format_frame(self, date, date_unit, datetime_frame):
875
875
json = df .to_json (date_format = "iso" )
876
876
result = read_json (json )
877
877
expected = df .copy ()
878
- expected .index = expected .index .tz_localize ("UTC" )
879
- expected ["date" ] = expected ["date" ].dt .tz_localize ("UTC" )
880
878
tm .assert_frame_equal (result , expected )
881
879
882
880
def test_date_format_frame_raises (self , datetime_frame ):
@@ -905,8 +903,6 @@ def test_date_format_series(self, date, date_unit, datetime_series):
905
903
json = ts .to_json (date_format = "iso" )
906
904
result = read_json (json , typ = "series" )
907
905
expected = ts .copy ()
908
- expected .index = expected .index .tz_localize ("UTC" )
909
- expected = expected .dt .tz_localize ("UTC" )
910
906
tm .assert_series_equal (result , expected )
911
907
912
908
def test_date_format_series_raises (self , datetime_series ):
@@ -1192,6 +1188,16 @@ def test_tz_is_utc(self, ts):
1192
1188
dt = ts .to_pydatetime ()
1193
1189
assert dumps (dt , iso_dates = True ) == exp
1194
1190
1191
+ def test_tz_is_naive (self ):
1192
+ from pandas .io .json import dumps
1193
+
1194
+ ts = Timestamp ("2013-01-10 05:00:00" )
1195
+ exp = '"2013-01-10T05:00:00.000"'
1196
+
1197
+ assert dumps (ts , iso_dates = True ) == exp
1198
+ dt = ts .to_pydatetime ()
1199
+ assert dumps (dt , iso_dates = True ) == exp
1200
+
1195
1201
@pytest .mark .parametrize (
1196
1202
"tz_range" ,
1197
1203
[
@@ -1212,10 +1218,31 @@ def test_tz_range_is_utc(self, tz_range):
1212
1218
1213
1219
assert dumps (tz_range , iso_dates = True ) == exp
1214
1220
dti = DatetimeIndex (tz_range )
1221
+ # Ensure datetimes in object array are serialized correctly
1222
+ # in addition to the normal DTI case
1223
+ assert dumps (dti , iso_dates = True ) == exp
1224
+ assert dumps (dti .astype (object ), iso_dates = True ) == exp
1225
+ df = DataFrame ({"DT" : dti })
1226
+ result = dumps (df , iso_dates = True )
1227
+ assert result == dfexp
1228
+ assert dumps (df .astype ({"DT" : object }), iso_dates = True )
1229
+
1230
+ def test_tz_range_is_naive (self ):
1231
+ from pandas .io .json import dumps
1232
+
1233
+ dti = pd .date_range ("2013-01-01 05:00:00" , periods = 2 )
1234
+
1235
+ exp = '["2013-01-01T05:00:00.000","2013-01-02T05:00:00.000"]'
1236
+ dfexp = '{"DT":{"0":"2013-01-01T05:00:00.000","1":"2013-01-02T05:00:00.000"}}'
1237
+
1238
+ # Ensure datetimes in object array are serialized correctly
1239
+ # in addition to the normal DTI case
1215
1240
assert dumps (dti , iso_dates = True ) == exp
1241
+ assert dumps (dti .astype (object ), iso_dates = True ) == exp
1216
1242
df = DataFrame ({"DT" : dti })
1217
1243
result = dumps (df , iso_dates = True )
1218
1244
assert result == dfexp
1245
+ assert dumps (df .astype ({"DT" : object }), iso_dates = True )
1219
1246
1220
1247
def test_read_inline_jsonl (self ):
1221
1248
# GH9180
0 commit comments