fix logicalType nullable date
MODIFY
fastavro/writer.py
fastavro/writer.py
@@ -261,14 +261,14 @@ def validate(datum, schema):
return (
(isinstance(datum, (int, long,)) and
INT_MIN_VALUE <= datum <= INT_MAX_VALUE) or
- isinstance(datum, (datetime.time, datetime.datetime))
+ isinstance(datum, (datetime.time, datetime.datetime, datetime.date))
)
if record_type == 'long':
return (
(isinstance(datum, (int, long,)) and
LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE) or
- isinstance(datum, (datetime.time, datetime.datetime))
+ isinstance(datum, (datetime.time, datetime.datetime, datetime.date))
)
if record_type in ['float', 'double']:

MODIFY
tests/test_logical_types.py
tests/test_logical_types.py
@@ -113,6 +113,18 @@ def test_null():
data2 = deserialize(schema_null, binary)
assert (data2['date'] is None)
+def test_not_null_datetime():
+ data1 = {'date': datetime.datetime(2017, 1, 1)}
+ binary = serialize(schema_null, data1)
+ data2 = deserialize(schema_null, binary)
+ assert (data2['date'] == datetime.date(2017, 1, 1))
+
+def test_not_null_date():
+ data1 = {'date': datetime.date(2017, 1, 1)}
+ binary = serialize(schema_null, data1)
+ data2 = deserialize(schema_null, binary)
+ assert (data2['date'] == datetime.date(2017, 1, 1))
+
schema_top = {
"name": "n",

fix logicalType nullable date