Convert iterables to list in cython array writing
* Convert iterables to list in cython array writing
In particular, I was trying to write tuples as arrays (the closest avro
type).
* Test for tuple encoding
* Fix whitespace style
MODIFY
fastavro/_write.pyx
fastavro/_write.pyx
@@ -326,6 +326,8 @@ cpdef write_data(bytearray fo, datum, schema):
elif record_type == 'enum':
return write_enum(fo, datum, schema)
elif record_type == 'array':
+ if not isinstance(datum, list):
+ datum = list(datum)
return write_array(fo, datum, schema)
elif record_type == 'map':
return write_map(fo, datum, schema)

MODIFY
tests/test_complex.py
tests/test_complex.py
@@ -122,3 +122,9 @@ def test_complex_schema_nulls():
{'multi_union_time': None, 'array_bytes_decimal': None,
'array_fixed_decimal': None, 'union_uuid': None})
assert (data1_compare == data2)
+
+
+def test_array_from_tuple():
+ data_list = serialize({"type": "array", "items": "int"}, [1, 2, 3])
+ data_tuple = serialize({"type": "array", "items": "int"}, (1, 2, 3))
+ assert data_list == data_tuple

Convert iterables to list in cython array writing (#441)

* Convert iterables to list in cython array writing

In particular, I was trying to write tuples as arrays (the closest avro
type).

* Test for tuple encoding

* Fix whitespace style