21
21
import pandas .compat as compat
22
22
23
23
import numpy as np
24
- from numpy .testing import (assert_array_equal ,
25
- assert_array_almost_equal_nulp ,
24
+ from numpy .testing import (assert_array_almost_equal_nulp ,
26
25
assert_approx_equal )
27
26
import pytz
28
27
import dateutil
@@ -166,15 +165,15 @@ def test_encodeArrayOfNestedArrays(self):
166
165
#self.assertEqual(output, json.dumps(input))
167
166
self .assertEqual (input , ujson .decode (output ))
168
167
input = np .array (input )
169
- assert_array_equal (input , ujson .decode (output , numpy = True , dtype = input .dtype ))
168
+ tm . assert_numpy_array_equal (input , ujson .decode (output , numpy = True , dtype = input .dtype ))
170
169
171
170
def test_encodeArrayOfDoubles (self ):
172
171
input = [ 31337.31337 , 31337.31337 , 31337.31337 , 31337.31337 ] * 10
173
172
output = ujson .encode (input )
174
173
self .assertEqual (input , json .loads (output ))
175
174
#self.assertEqual(output, json.dumps(input))
176
175
self .assertEqual (input , ujson .decode (output ))
177
- assert_array_equal (np .array (input ), ujson .decode (output , numpy = True ))
176
+ tm . assert_numpy_array_equal (np .array (input ), ujson .decode (output , numpy = True ))
178
177
179
178
def test_doublePrecisionTest (self ):
180
179
input = 30.012345678901234
@@ -271,7 +270,7 @@ def test_encodeArrayInArray(self):
271
270
self .assertEqual (input , json .loads (output ))
272
271
self .assertEqual (output , json .dumps (input ))
273
272
self .assertEqual (input , ujson .decode (output ))
274
- assert_array_equal (np .array (input ), ujson .decode (output , numpy = True ))
273
+ tm . assert_numpy_array_equal (np .array (input ), ujson .decode (output , numpy = True ))
275
274
pass
276
275
277
276
def test_encodeIntConversion (self ):
@@ -307,7 +306,7 @@ def test_encodeListConversion(self):
307
306
output = ujson .encode (input )
308
307
self .assertEqual (input , json .loads (output ))
309
308
self .assertEqual (input , ujson .decode (output ))
310
- assert_array_equal (np .array (input ), ujson .decode (output , numpy = True ))
309
+ tm . assert_numpy_array_equal (np .array (input ), ujson .decode (output , numpy = True ))
311
310
pass
312
311
313
312
def test_encodeDictConversion (self ):
@@ -676,8 +675,8 @@ def test_encodeListLongConversion(self):
676
675
output = ujson .encode (input )
677
676
self .assertEqual (input , json .loads (output ))
678
677
self .assertEqual (input , ujson .decode (output ))
679
- assert_array_equal (np .array (input ), ujson .decode (output , numpy = True ,
680
- dtype = np .int64 ))
678
+ tm . assert_numpy_array_equal (np .array (input ), ujson .decode (output , numpy = True ,
679
+ dtype = np .int64 ))
681
680
pass
682
681
683
682
def test_encodeLongConversion (self ):
@@ -755,7 +754,7 @@ def test_loadFile(self):
755
754
f = StringIO ("[1,2,3,4]" )
756
755
self .assertEqual ([1 , 2 , 3 , 4 ], ujson .load (f ))
757
756
f = StringIO ("[1,2,3,4]" )
758
- assert_array_equal (np .array ([1 , 2 , 3 , 4 ]), ujson .load (f , numpy = True ))
757
+ tm . assert_numpy_array_equal (np .array ([1 , 2 , 3 , 4 ]), ujson .load (f , numpy = True ))
759
758
760
759
def test_loadFileLikeObject (self ):
761
760
class filelike :
@@ -768,7 +767,7 @@ def read(self):
768
767
f = filelike ()
769
768
self .assertEqual ([1 , 2 , 3 , 4 ], ujson .load (f ))
770
769
f = filelike ()
771
- assert_array_equal (np .array ([1 , 2 , 3 , 4 ]), ujson .load (f , numpy = True ))
770
+ tm . assert_numpy_array_equal (np .array ([1 , 2 , 3 , 4 ]), ujson .load (f , numpy = True ))
772
771
773
772
def test_loadFileArgsError (self ):
774
773
try :
@@ -906,7 +905,7 @@ def testBoolArray(self):
906
905
inpt = np .array ([True , False , True , True , False , True , False , False ],
907
906
dtype = np .bool )
908
907
outp = np .array (ujson .decode (ujson .encode (inpt )), dtype = np .bool )
909
- assert_array_equal (inpt , outp )
908
+ tm . assert_numpy_array_equal (inpt , outp )
910
909
911
910
def testInt (self ):
912
911
num = np .int (2562010 )
@@ -943,7 +942,7 @@ def testIntArray(self):
943
942
for dtype in dtypes :
944
943
inpt = arr .astype (dtype )
945
944
outp = np .array (ujson .decode (ujson .encode (inpt )), dtype = dtype )
946
- assert_array_equal (inpt , outp )
945
+ tm . assert_numpy_array_equal (inpt , outp )
947
946
948
947
def testIntMax (self ):
949
948
num = np .int (np .iinfo (np .int ).max )
@@ -1008,26 +1007,26 @@ def testArrays(self):
1008
1007
arr = np .arange (100 );
1009
1008
1010
1009
arr = arr .reshape ((10 , 10 ))
1011
- assert_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1012
- assert_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1010
+ tm . assert_numpy_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1011
+ tm . assert_numpy_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1013
1012
1014
1013
arr = arr .reshape ((5 , 5 , 4 ))
1015
- assert_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1016
- assert_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1014
+ tm . assert_numpy_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1015
+ tm . assert_numpy_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1017
1016
1018
1017
arr = arr .reshape ((100 , 1 ))
1019
- assert_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1020
- assert_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1018
+ tm . assert_numpy_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1019
+ tm . assert_numpy_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1021
1020
1022
1021
arr = np .arange (96 );
1023
1022
arr = arr .reshape ((2 , 2 , 2 , 2 , 3 , 2 ))
1024
- assert_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1025
- assert_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1023
+ tm . assert_numpy_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1024
+ tm . assert_numpy_array_equal (ujson .decode (ujson .encode (arr ), numpy = True ), arr )
1026
1025
1027
1026
l = ['a' , list (), dict (), dict (), list (),
1028
1027
42 , 97.8 , ['a' , 'b' ], {'key' : 'val' }]
1029
1028
arr = np .array (l )
1030
- assert_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1029
+ tm . assert_numpy_array_equal (np .array (ujson .decode (ujson .encode (arr ))), arr )
1031
1030
1032
1031
arr = np .arange (100.202 , 200.202 , 1 , dtype = np .float32 );
1033
1032
arr = arr .reshape ((5 , 5 , 4 ))
@@ -1158,49 +1157,49 @@ def testDataFrame(self):
1158
1157
# column indexed
1159
1158
outp = DataFrame (ujson .decode (ujson .encode (df )))
1160
1159
self .assertTrue ((df == outp ).values .all ())
1161
- assert_array_equal (df .columns , outp .columns )
1162
- assert_array_equal (df .index , outp .index )
1160
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1161
+ tm . assert_numpy_array_equal (df .index , outp .index )
1163
1162
1164
1163
dec = _clean_dict (ujson .decode (ujson .encode (df , orient = "split" )))
1165
1164
outp = DataFrame (** dec )
1166
1165
self .assertTrue ((df == outp ).values .all ())
1167
- assert_array_equal (df .columns , outp .columns )
1168
- assert_array_equal (df .index , outp .index )
1166
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1167
+ tm . assert_numpy_array_equal (df .index , outp .index )
1169
1168
1170
1169
outp = DataFrame (ujson .decode (ujson .encode (df , orient = "records" )))
1171
1170
outp .index = df .index
1172
1171
self .assertTrue ((df == outp ).values .all ())
1173
- assert_array_equal (df .columns , outp .columns )
1172
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1174
1173
1175
1174
outp = DataFrame (ujson .decode (ujson .encode (df , orient = "values" )))
1176
1175
outp .index = df .index
1177
1176
self .assertTrue ((df .values == outp .values ).all ())
1178
1177
1179
1178
outp = DataFrame (ujson .decode (ujson .encode (df , orient = "index" )))
1180
1179
self .assertTrue ((df .transpose () == outp ).values .all ())
1181
- assert_array_equal (df .transpose ().columns , outp .columns )
1182
- assert_array_equal (df .transpose ().index , outp .index )
1180
+ tm . assert_numpy_array_equal (df .transpose ().columns , outp .columns )
1181
+ tm . assert_numpy_array_equal (df .transpose ().index , outp .index )
1183
1182
1184
1183
def testDataFrameNumpy (self ):
1185
1184
df = DataFrame ([[1 ,2 ,3 ], [4 ,5 ,6 ]], index = ['a' , 'b' ], columns = ['x' , 'y' , 'z' ])
1186
1185
1187
1186
# column indexed
1188
1187
outp = DataFrame (ujson .decode (ujson .encode (df ), numpy = True ))
1189
1188
self .assertTrue ((df == outp ).values .all ())
1190
- assert_array_equal (df .columns , outp .columns )
1191
- assert_array_equal (df .index , outp .index )
1189
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1190
+ tm . assert_numpy_array_equal (df .index , outp .index )
1192
1191
1193
1192
dec = _clean_dict (ujson .decode (ujson .encode (df , orient = "split" ),
1194
1193
numpy = True ))
1195
1194
outp = DataFrame (** dec )
1196
1195
self .assertTrue ((df == outp ).values .all ())
1197
- assert_array_equal (df .columns , outp .columns )
1198
- assert_array_equal (df .index , outp .index )
1196
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1197
+ tm . assert_numpy_array_equal (df .index , outp .index )
1199
1198
1200
1199
outp = DataFrame (ujson .decode (ujson .encode (df , orient = "index" ), numpy = True ))
1201
1200
self .assertTrue ((df .transpose () == outp ).values .all ())
1202
- assert_array_equal (df .transpose ().columns , outp .columns )
1203
- assert_array_equal (df .transpose ().index , outp .index )
1201
+ tm . assert_numpy_array_equal (df .transpose ().columns , outp .columns )
1202
+ tm . assert_numpy_array_equal (df .transpose ().index , outp .index )
1204
1203
1205
1204
def testDataFrameNested (self ):
1206
1205
df = DataFrame ([[1 ,2 ,3 ], [4 ,5 ,6 ]], index = ['a' , 'b' ], columns = ['x' , 'y' , 'z' ])
@@ -1233,18 +1232,18 @@ def testDataFrameNumpyLabelled(self):
1233
1232
# column indexed
1234
1233
outp = DataFrame (* ujson .decode (ujson .encode (df ), numpy = True , labelled = True ))
1235
1234
self .assertTrue ((df .T == outp ).values .all ())
1236
- assert_array_equal (df .T .columns , outp .columns )
1237
- assert_array_equal (df .T .index , outp .index )
1235
+ tm . assert_numpy_array_equal (df .T .columns , outp .columns )
1236
+ tm . assert_numpy_array_equal (df .T .index , outp .index )
1238
1237
1239
1238
outp = DataFrame (* ujson .decode (ujson .encode (df , orient = "records" ), numpy = True , labelled = True ))
1240
1239
outp .index = df .index
1241
1240
self .assertTrue ((df == outp ).values .all ())
1242
- assert_array_equal (df .columns , outp .columns )
1241
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1243
1242
1244
1243
outp = DataFrame (* ujson .decode (ujson .encode (df , orient = "index" ), numpy = True , labelled = True ))
1245
1244
self .assertTrue ((df == outp ).values .all ())
1246
- assert_array_equal (df .columns , outp .columns )
1247
- assert_array_equal (df .index , outp .index )
1245
+ tm . assert_numpy_array_equal (df .columns , outp .columns )
1246
+ tm . assert_numpy_array_equal (df .index , outp .index )
1248
1247
1249
1248
def testSeries (self ):
1250
1249
s = Series ([10 , 20 , 30 , 40 , 50 , 60 ], name = "series" , index = [6 ,7 ,8 ,9 ,10 ,15 ])
0 commit comments