Skip to content

Commit 2396370

Browse files
committed
Merge pull request #10853 from kawochen/TST-FIX-10837
TST: GH10837 remove test_ujson.py reliance on dict iteration order
2 parents 94ec946 + 9c60d18 commit 2396370

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

pandas/io/tests/test_json/test_ujson.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -1131,22 +1131,20 @@ def testArrayNumpyLabelled(self):
11311131
self.assertTrue(output[1] is None)
11321132
self.assertTrue((np.array([u('a')]) == output[2]).all())
11331133

1134-
# py3 is non-determinstic on the ordering......
1135-
if not compat.PY3:
1136-
input = [{'a': 42, 'b':31}, {'a': 24, 'c': 99}, {'a': 2.4, 'b': 78}]
1137-
output = ujson.loads(ujson.dumps(input), numpy=True, labelled=True)
1138-
expectedvals = np.array([42, 31, 24, 99, 2.4, 78], dtype=int).reshape((3,2))
1139-
self.assertTrue((expectedvals == output[0]).all())
1140-
self.assertTrue(output[1] is None)
1141-
self.assertTrue((np.array([u('a'), 'b']) == output[2]).all())
1142-
1143-
1144-
input = {1: {'a': 42, 'b':31}, 2: {'a': 24, 'c': 99}, 3: {'a': 2.4, 'b': 78}}
1145-
output = ujson.loads(ujson.dumps(input), numpy=True, labelled=True)
1146-
expectedvals = np.array([42, 31, 24, 99, 2.4, 78], dtype=int).reshape((3,2))
1147-
self.assertTrue((expectedvals == output[0]).all())
1148-
self.assertTrue((np.array(['1','2','3']) == output[1]).all())
1149-
self.assertTrue((np.array(['a', 'b']) == output[2]).all())
1134+
# Write out the dump explicitly so there is no dependency on iteration order GH10837
1135+
input_dumps = '[{"a": 42, "b":31}, {"a": 24, "c": 99}, {"a": 2.4, "b": 78}]'
1136+
output = ujson.loads(input_dumps, numpy=True, labelled=True)
1137+
expectedvals = np.array([42, 31, 24, 99, 2.4, 78], dtype=int).reshape((3, 2))
1138+
self.assertTrue((expectedvals == output[0]).all())
1139+
self.assertTrue(output[1] is None)
1140+
self.assertTrue((np.array([u('a'), 'b']) == output[2]).all())
1141+
1142+
input_dumps = '{"1": {"a": 42, "b":31}, "2": {"a": 24, "c": 99}, "3": {"a": 2.4, "b": 78}}'
1143+
output = ujson.loads(input_dumps, numpy=True, labelled=True)
1144+
expectedvals = np.array([42, 31, 24, 99, 2.4, 78], dtype=int).reshape((3, 2))
1145+
self.assertTrue((expectedvals == output[0]).all())
1146+
self.assertTrue((np.array(['1', '2', '3']) == output[1]).all())
1147+
self.assertTrue((np.array(['a', 'b']) == output[2]).all())
11501148

11511149

11521150
class PandasJSONTests(TestCase):

0 commit comments

Comments
 (0)