28
28
StringArray ,
29
29
)
30
30
31
+ from pandas .io .json import ujson_dumps
32
+
31
33
32
34
def test_literal_json_deprecation ():
33
35
# PR 53409
@@ -865,14 +867,13 @@ def test_date_index_and_values(self, date_format, as_object, date_typ):
865
867
)
866
868
def test_convert_dates_infer (self , infer_word ):
867
869
# GH10747
868
- from pandas .io .json import dumps
869
870
870
871
data = [{"id" : 1 , infer_word : 1036713600000 }, {"id" : 2 }]
871
872
expected = DataFrame (
872
873
[[1 , Timestamp ("2002-11-08" )], [2 , pd .NaT ]], columns = ["id" , infer_word ]
873
874
)
874
875
875
- result = read_json (StringIO (dumps (data )))[["id" , infer_word ]]
876
+ result = read_json (StringIO (ujson_dumps (data )))[["id" , infer_word ]]
876
877
tm .assert_frame_equal (result , expected )
877
878
878
879
@pytest .mark .parametrize (
@@ -1133,8 +1134,6 @@ def test_default_handler(self):
1133
1134
tm .assert_frame_equal (expected , result , check_index_type = False )
1134
1135
1135
1136
def test_default_handler_indirect (self ):
1136
- from pandas .io .json import dumps
1137
-
1138
1137
def default (obj ):
1139
1138
if isinstance (obj , complex ):
1140
1139
return [("mathjs" , "Complex" ), ("re" , obj .real ), ("im" , obj .imag )]
@@ -1151,7 +1150,9 @@ def default(obj):
1151
1150
'[9,[[1,null],["STR",null],[[["mathjs","Complex"],'
1152
1151
'["re",4.0],["im",-5.0]],"N\\ /A"]]]'
1153
1152
)
1154
- assert dumps (df_list , default_handler = default , orient = "values" ) == expected
1153
+ assert (
1154
+ ujson_dumps (df_list , default_handler = default , orient = "values" ) == expected
1155
+ )
1155
1156
1156
1157
def test_default_handler_numpy_unsupported_dtype (self ):
1157
1158
# GH12554 to_json raises 'Unhandled numpy dtype 15'
@@ -1235,23 +1236,19 @@ def test_sparse(self):
1235
1236
],
1236
1237
)
1237
1238
def test_tz_is_utc (self , ts ):
1238
- from pandas .io .json import dumps
1239
-
1240
1239
exp = '"2013-01-10T05:00:00.000Z"'
1241
1240
1242
- assert dumps (ts , iso_dates = True ) == exp
1241
+ assert ujson_dumps (ts , iso_dates = True ) == exp
1243
1242
dt = ts .to_pydatetime ()
1244
- assert dumps (dt , iso_dates = True ) == exp
1243
+ assert ujson_dumps (dt , iso_dates = True ) == exp
1245
1244
1246
1245
def test_tz_is_naive (self ):
1247
- from pandas .io .json import dumps
1248
-
1249
1246
ts = Timestamp ("2013-01-10 05:00:00" )
1250
1247
exp = '"2013-01-10T05:00:00.000"'
1251
1248
1252
- assert dumps (ts , iso_dates = True ) == exp
1249
+ assert ujson_dumps (ts , iso_dates = True ) == exp
1253
1250
dt = ts .to_pydatetime ()
1254
- assert dumps (dt , iso_dates = True ) == exp
1251
+ assert ujson_dumps (dt , iso_dates = True ) == exp
1255
1252
1256
1253
@pytest .mark .parametrize (
1257
1254
"tz_range" ,
@@ -1262,42 +1259,38 @@ def test_tz_is_naive(self):
1262
1259
],
1263
1260
)
1264
1261
def test_tz_range_is_utc (self , tz_range ):
1265
- from pandas .io .json import dumps
1266
-
1267
1262
exp = '["2013-01-01T05:00:00.000Z","2013-01-02T05:00:00.000Z"]'
1268
1263
dfexp = (
1269
1264
'{"DT":{'
1270
1265
'"0":"2013-01-01T05:00:00.000Z",'
1271
1266
'"1":"2013-01-02T05:00:00.000Z"}}'
1272
1267
)
1273
1268
1274
- assert dumps (tz_range , iso_dates = True ) == exp
1269
+ assert ujson_dumps (tz_range , iso_dates = True ) == exp
1275
1270
dti = DatetimeIndex (tz_range )
1276
1271
# Ensure datetimes in object array are serialized correctly
1277
1272
# in addition to the normal DTI case
1278
- assert dumps (dti , iso_dates = True ) == exp
1279
- assert dumps (dti .astype (object ), iso_dates = True ) == exp
1273
+ assert ujson_dumps (dti , iso_dates = True ) == exp
1274
+ assert ujson_dumps (dti .astype (object ), iso_dates = True ) == exp
1280
1275
df = DataFrame ({"DT" : dti })
1281
- result = dumps (df , iso_dates = True )
1276
+ result = ujson_dumps (df , iso_dates = True )
1282
1277
assert result == dfexp
1283
- assert dumps (df .astype ({"DT" : object }), iso_dates = True )
1278
+ assert ujson_dumps (df .astype ({"DT" : object }), iso_dates = True )
1284
1279
1285
1280
def test_tz_range_is_naive (self ):
1286
- from pandas .io .json import dumps
1287
-
1288
1281
dti = pd .date_range ("2013-01-01 05:00:00" , periods = 2 )
1289
1282
1290
1283
exp = '["2013-01-01T05:00:00.000","2013-01-02T05:00:00.000"]'
1291
1284
dfexp = '{"DT":{"0":"2013-01-01T05:00:00.000","1":"2013-01-02T05:00:00.000"}}'
1292
1285
1293
1286
# Ensure datetimes in object array are serialized correctly
1294
1287
# in addition to the normal DTI case
1295
- assert dumps (dti , iso_dates = True ) == exp
1296
- assert dumps (dti .astype (object ), iso_dates = True ) == exp
1288
+ assert ujson_dumps (dti , iso_dates = True ) == exp
1289
+ assert ujson_dumps (dti .astype (object ), iso_dates = True ) == exp
1297
1290
df = DataFrame ({"DT" : dti })
1298
- result = dumps (df , iso_dates = True )
1291
+ result = ujson_dumps (df , iso_dates = True )
1299
1292
assert result == dfexp
1300
- assert dumps (df .astype ({"DT" : object }), iso_dates = True )
1293
+ assert ujson_dumps (df .astype ({"DT" : object }), iso_dates = True )
1301
1294
1302
1295
def test_read_inline_jsonl (self ):
1303
1296
# GH9180
0 commit comments