You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2018/11/27 13:36:10 UTC

[arrow] branch master updated: ARROW-3889: [Python] Crash when creating schema from invalid args

This is an automated email from the ASF dual-hosted git repository.

apitrou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 1020e0b  ARROW-3889: [Python] Crash when creating schema from invalid args
1020e0b is described below

commit 1020e0b45c4536978b9ba6a0c38e312082a00fc7
Author: Antoine Pitrou <an...@python.org>
AuthorDate: Tue Nov 27 14:35:56 2018 +0100

    ARROW-3889: [Python] Crash when creating schema from invalid args
    
    Author: Antoine Pitrou <an...@python.org>
    
    Closes #3038 from pitrou/ARROW-3889-py-schema-crash and squashes the following commits:
    
    eff674ba <Antoine Pitrou> ARROW-3889:  Crash when creating schema
---
 python/pyarrow/tests/test_schema.py | 10 ++++++++++
 python/pyarrow/tests/test_types.py  | 10 ++++++++++
 python/pyarrow/types.pxi            |  4 +++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/python/pyarrow/tests/test_schema.py b/python/pyarrow/tests/test_schema.py
index d358f12..5385c3c 100644
--- a/python/pyarrow/tests/test_schema.py
+++ b/python/pyarrow/tests/test_schema.py
@@ -221,6 +221,9 @@ bar: string
 baz: list<item: int8>
   child 0, item: int8"""
 
+    with pytest.raises(TypeError):
+        pa.schema([None])
+
 
 def test_schema_from_tuples():
     fields = [
@@ -238,6 +241,9 @@ bar: string
 baz: list<item: int8>
   child 0, item: int8"""
 
+    with pytest.raises(TypeError):
+        pa.schema([('foo', None)])
+
 
 def test_schema_from_mapping():
     fields = OrderedDict([
@@ -255,6 +261,10 @@ bar: string
 baz: list<item: int8>
   child 0, item: int8"""
 
+    fields = OrderedDict([('foo', None)])
+    with pytest.raises(TypeError):
+        pa.schema(fields)
+
 
 def test_field_flatten():
     f0 = pa.field('foo', pa.int32()).add_metadata({b'foo': b'bar'})
diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index b15cb57..176ce87 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -223,6 +223,9 @@ def test_list_type():
     ty = pa.list_(pa.int64())
     assert ty.value_type == pa.int64()
 
+    with pytest.raises(TypeError):
+        pa.list_(None)
+
 
 def test_struct_type():
     fields = [pa.field('a', pa.int64()),
@@ -265,6 +268,10 @@ def test_struct_type():
     for a, b in zip(ty, fields):
         a == b
 
+    # Invalid args
+    with pytest.raises(TypeError):
+        pa.struct([('a', None)])
+
 
 def test_union_type():
     def check_fields(ty, fields):
@@ -409,6 +416,9 @@ def test_field_basic():
     f = pa.field('foo', t, False)
     assert not f.nullable
 
+    with pytest.raises(TypeError):
+        pa.field('foo', None)
+
 
 def test_field_equals():
     meta1 = {b'foo': b'bar'}
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index 726bf0c..d5d99e4 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -1288,7 +1288,7 @@ cpdef ListType list_(value_type):
     elif isinstance(value_type, Field):
         list_type.reset(new CListType((<Field> value_type).sp_field))
     else:
-        raise ValueError('List requires DataType or Field')
+        raise TypeError('List requires DataType or Field')
 
     out.init(list_type)
     return out
@@ -1535,6 +1535,8 @@ def schema(fields, dict metadata=None):
             py_field = field(*item)
         else:
             py_field = item
+        if py_field is None:
+            raise TypeError("field or tuple expected, got None")
         c_fields.push_back(py_field.sp_field)
 
     if metadata is not None: