|
34 | 34 | try:
|
35 | 35 | import pandas
|
36 | 36 | BINARY = None
|
37 |
| - |
| 37 | + |
38 | 38 | PANDAS_EXPRESSIONS = OrderedDict((
|
39 | 39 | (b'("G"$"8c680a01-5a49-5aab-5a65-d4bfddb6a661"; 0Ng)',
|
40 | 40 | {'data': pandas.Series(numpy.array([uuid.UUID('8c680a01-5a49-5aab-5a65-d4bfddb6a661'), numpy.nan])),
|
|
49 | 49 | [b'quick', b'brown', b'fox', b'jumps', b'over', b'a lazy', b'dog']),
|
50 | 50 | (b'("quick"; " "; "fox"; "jumps"; "over"; "a lazy"; "dog")',
|
51 | 51 | [b'quick', numpy.nan, b'fox', b'jumps', b'over', b'a lazy', b'dog']),
|
52 |
| - |
| 52 | + |
53 | 53 | (b'(0b;1b;0b)', {'data': pandas.Series(numpy.array([False, True, False], dtype = numpy.bool)),
|
54 | 54 | 'meta': MetaData(qtype = QBOOL_LIST) }),
|
55 | 55 | (b'(0x01;0x02;0xff)', {'data': pandas.Series(numpy.array([1, 2, 0xff], dtype = numpy.int8)),
|
|
78 | 78 | 'meta': MetaData(qtype = QDOUBLE_LIST) }),
|
79 | 79 | (b'3.23 0n', {'data': pandas.Series(numpy.array([3.23, numpy.nan])),
|
80 | 80 | 'meta': MetaData(qtype = QDOUBLE_LIST) }),
|
81 |
| - |
| 81 | + |
82 | 82 | (b'(2001.01m; 0Nm)', {'data': pandas.Series(numpy.array([numpy.datetime64('2001-01'), numpy.datetime64('NaT')], dtype='datetime64[M]')),
|
83 | 83 | 'meta': MetaData(qtype = QMONTH_LIST) }),
|
84 | 84 | (b'2001.01.01 2000.05.01 0Nd', {'data': pandas.Series(numpy.array([numpy.datetime64('2001-01-01'), numpy.datetime64('2000-05-01'), numpy.datetime64('NaT')], dtype='datetime64[D]')),
|
|
95 | 95 | 'meta': MetaData(qtype = QTIMESTAMP_LIST) }),
|
96 | 96 | (b'0D05:36:57.600 0Nn', {'data': pandas.Series(numpy.array([numpy.timedelta64(20217600000000, 'ns'), numpy.timedelta64('nat', 'ns')])),
|
97 | 97 | 'meta': MetaData(qtype = QTIMESPAN_LIST) }),
|
98 |
| - |
| 98 | + |
99 | 99 | (b'1 2!`abc`cdefgh', QDictionary(qlist(numpy.array([1, 2], dtype=numpy.int64), qtype=QLONG_LIST),
|
100 | 100 | qlist(numpy.array(['abc', 'cdefgh']), qtype = QSYMBOL_LIST))),
|
101 | 101 | (b'(0 1; 2 3)!`first`second', QDictionary([qlist(numpy.array([0, 1], dtype=numpy.int64), qtype=QLONG_LIST), qlist(numpy.array([2, 3], dtype=numpy.int64), qtype=QLONG_LIST)],
|
|
121 | 121 | ))
|
122 | 122 | ),
|
123 | 123 | 'meta': MetaData(**{'qtype': QTABLE, 'name': QSYMBOL_LIST, 'iq': QLONG_LIST, 'grade': QSTRING}) }),
|
| 124 | + (b'1#([] sym:`x`x`x;str:" a")', |
| 125 | + {'data': pandas.DataFrame(OrderedDict((('sym', pandas.Series(['x'], dtype = numpy.string_)), |
| 126 | + ('str', pandas.Series([' '], dtype = numpy.str).replace(b' ', numpy.nan)), |
| 127 | + )) |
| 128 | + ), |
| 129 | + 'meta': MetaData(**{'qtype': QTABLE, 'sym': QSYMBOL_LIST, 'str': QSTRING}), |
| 130 | + 'single_char_strings': True}), |
| 131 | + (b'-1#([] sym:`x`x`x;str:" a")', |
| 132 | + {'data': pandas.DataFrame(OrderedDict((('sym', pandas.Series(['x'], dtype = numpy.string_)), |
| 133 | + ('str', pandas.Series(['a'], dtype = numpy.str)), |
| 134 | + )) |
| 135 | + ), |
| 136 | + 'meta': MetaData(**{'qtype': QTABLE, 'sym': QSYMBOL_LIST, 'str': QSTRING}), |
| 137 | + 'single_char_strings': True}), |
| 138 | + (b'2#([] sym:`x`x`x`x;str:" aa")', |
| 139 | + {'data': pandas.DataFrame(OrderedDict((('sym', pandas.Series(['x', 'x'], dtype = numpy.string_)), |
| 140 | + ('str', pandas.Series([' ', ' '], dtype = numpy.str).replace(b' ', numpy.nan)), |
| 141 | + )) |
| 142 | + ), |
| 143 | + 'meta': MetaData(**{'qtype': QTABLE, 'sym': QSYMBOL_LIST, 'str': QSTRING})}), |
| 144 | + (b'-2#([] sym:`x`x`x`x;str:" aa")', |
| 145 | + {'data': pandas.DataFrame(OrderedDict((('sym', pandas.Series(['x', 'x'], dtype = numpy.string_)), |
| 146 | + ('str', pandas.Series(['a', 'a'], dtype = numpy.str).replace(b' ', numpy.nan)), |
| 147 | + )) |
| 148 | + ), |
| 149 | + 'meta': MetaData(**{'qtype': QTABLE, 'sym': QSYMBOL_LIST, 'str': QSTRING})}), |
124 | 150 | (b'flip `name`iq`fullname!(`Dent`Beeblebrox`Prefect;98 42 126;("Arthur Dent"; "Zaphod Beeblebrox"; "Ford Prefect"))',
|
125 | 151 | {'data': pandas.DataFrame(OrderedDict((('name', pandas.Series(['Dent', 'Beeblebrox', 'Prefect'], dtype = numpy.string_)),
|
126 | 152 | ('iq', pandas.Series(numpy.array([98, 42, 126], dtype = numpy.int64))),
|
|
147 | 173 | ('iq', pandas.Series(numpy.array([], dtype = numpy.int32)))))
|
148 | 174 | ),
|
149 | 175 | 'meta': MetaData(**{'qtype': QTABLE, 'name': QSYMBOL_LIST, 'iq': QINT_LIST}) }),
|
150 |
| - |
151 | 176 | (b'([] pos:`d1`d2`d3;dates:(2001.01.01;2000.05.01;0Nd))',
|
152 | 177 | {'data': pandas.DataFrame(OrderedDict((('pos', pandas.Series(numpy.array(['d1', 'd2', 'd3'], dtype = numpy.string_))),
|
153 | 178 | ('dates', pandas.Series(numpy.array([numpy.datetime64('2001-01-01'), numpy.datetime64('2000-05-01'), numpy.datetime64('NaT')], dtype='datetime64[D]')))))
|
@@ -276,15 +301,18 @@ def test_writing_pandas():
|
276 | 301 |
|
277 | 302 | for query, value in iter(PANDAS_EXPRESSIONS.items()):
|
278 | 303 | sys.stdout.write( '%-75s' % query )
|
| 304 | + single_char_strings = False |
279 | 305 | if isinstance(value, dict):
|
280 | 306 | data = value['data']
|
281 | 307 | if 'index' in value:
|
282 | 308 | data = data.reset_index(drop = True)
|
283 | 309 | data = data.set_index(value['index'])
|
| 310 | + if 'single_char_strings' in value: |
| 311 | + single_char_strings = value['single_char_strings'] |
284 | 312 | data.meta = value['meta']
|
285 | 313 | else:
|
286 | 314 | data = value
|
287 |
| - serialized = binascii.hexlify(w.write(data, 1))[16:].lower() |
| 315 | + serialized = binascii.hexlify(w.write(data, 1, single_char_strings = single_char_strings))[16:].lower() |
288 | 316 | assert serialized == BINARY[query].lower(), 'serialization failed: %s, expected: %s actual: %s' % (value, BINARY[query].lower(), serialized)
|
289 | 317 | sys.stdout.write( '.' )
|
290 | 318 |
|
@@ -312,8 +340,3 @@ def test_writing_pandas():
|
312 | 340 | test_writing_pandas()
|
313 | 341 | except ImportError:
|
314 | 342 | pandas = None
|
315 |
| - |
316 |
| - |
317 |
| - |
318 |
| - |
319 |
| - |
|
0 commit comments