PERF: json support for blocks GH9037 · pandas-dev/pandas@a67bef4 (original) (raw)
1
1
`# pylint: disable-msg=W0612,E1101
`
2
``
`-
from pandas.compat import range, lrange, StringIO
`
``
2
`+
from pandas.compat import range, lrange, StringIO, OrderedDict
`
3
3
`from pandas import compat
`
4
4
`import os
`
5
5
``
`@@ -337,14 +337,44 @@ def test_v12_compat(self):
`
337
337
``
338
338
`v12_json = os.path.join(self.dirpath, 'tsframe_v012.json')
`
339
339
`df_unser = pd.read_json(v12_json)
`
340
``
`-
df_unser = pd.read_json(v12_json)
`
341
340
`assert_frame_equal(df, df_unser)
`
342
341
``
343
342
`df_iso = df.drop(['modified'], axis=1)
`
344
343
`v12_iso_json = os.path.join(self.dirpath, 'tsframe_iso_v012.json')
`
345
344
`df_unser_iso = pd.read_json(v12_iso_json)
`
346
345
`assert_frame_equal(df_iso, df_unser_iso)
`
347
346
``
``
347
`+
def test_blocks_compat_GH9037(self):
`
``
348
`+
index = pd.date_range('20000101', periods=10, freq='H')
`
``
349
`+
df_mixed = DataFrame(OrderedDict(
`
``
350
`+
float_1=[-0.92077639, 0.77434435, 1.25234727, 0.61485564,
`
``
351
`+
-0.60316077, 0.24653374, 0.28668979, -2.51969012,
`
``
352
`+
0.95748401, -1.02970536],
`
``
353
`+
int_1=[19680418, 75337055, 99973684, 65103179, 79373900,
`
``
354
`+
40314334, 21290235, 4991321, 41903419, 16008365],
`
``
355
`+
str_1=['78c608f1', '64a99743', '13d2ff52', 'ca7f4af2', '97236474',
`
``
356
`+
'bde7e214', '1a6bde47', 'b1190be5', '7a669144', '8d64d068'],
`
``
357
`+
float_2=[-0.0428278, -1.80872357, 3.36042349, -0.7573685,
`
``
358
`+
-0.48217572, 0.86229683, 1.08935819, 0.93898739,
`
``
359
`+
-0.03030452, 1.43366348],
`
``
360
`+
str_2=['14f04af9', 'd085da90', '4bcfac83', '81504caf', '2ffef4a9',
`
``
361
`+
'08e2f5c4', '07e1af03', 'addbd4a7', '1f6a09ba', '4bfc4d87'],
`
``
362
`+
int_2=[86967717, 98098830, 51927505, 20372254, 12601730, 20884027,
`
``
363
`+
34193846, 10561746, 24867120, 76131025]
`
``
364
`+
), index=index)
`
``
365
+
``
366
`+
JSON deserialisation always creates unicode strings
`
``
367
`+
df_mixed.columns = df_mixed.columns.astype('unicode')
`
``
368
+
``
369
`+
df_roundtrip = pd.read_json(df_mixed.to_json(orient='split'),
`
``
370
`+
orient='split')
`
``
371
`+
assert_frame_equal(df_mixed, df_roundtrip,
`
``
372
`+
check_index_type=True,
`
``
373
`+
check_column_type=True,
`
``
374
`+
check_frame_type=True,
`
``
375
`+
by_blocks=True,
`
``
376
`+
check_exact=True)
`
``
377
+
348
378
`def test_series_non_unique_index(self):
`
349
379
`s = Series(['a', 'b'], index=[1, 1])
`
350
380
``