def test_null_types(self):
"""
Test to validate that the numpy protocol handler can deal with null values.
@since 3.3.0
- updated 3.6.0: now numeric types used masked array
@jira_ticket PYTHON-550
@expected_result Numpy can handle non mapped types' null values.
@test_category data_types:serialization
"""
s = self.session
s.client_protocol_handler = NumpyProtocolHandler
table = "%s.%s" % (self.keyspace_name, self.function_table_name)
create_table_with_all_types(table, s, 10)
begin_unset = max(s.execute('select primkey from %s' % (table,))[0]['primkey']) + 1
keys_null = range(begin_unset, begin_unset + 10)
# scatter some emptry rows in here
insert = "insert into %s (primkey) values (%%s)" % (table,)
execute_concurrent_with_args(s, insert, ((k,) for k in keys_null))
result = s.execute("select * from %s" % (table,))[0]
from numpy.ma import masked, MaskedArray
result_keys = result.pop('primkey')
mapped_index = [v[1] for v in sorted(zip(result_keys, count()))]
had_masked = had_none = False
for col_array in result.values():
# these have to be different branches (as opposed to comparing against an 'unset value')
# because None and `masked` have different identity and equals semantics
if isinstance(col_array, MaskedArray):
had_masked = True
[self.assertIsNot(col_array[i], masked) for i in mapped_index[:begin_unset]]
[self.assertIs(col_array[i], masked) for i in mapped_index[begin_unset:]]
else:
had_none = True
[self.assertIsNotNone(col_array[i]) for i in mapped_index[:begin_unset]]
[self.assertIsNone(col_array[i]) for i in mapped_index[begin_unset:]]
self.assertTrue(had_masked)
self.assertTrue(had_none)
test_cython_protocol_handlers.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录