You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/08/09 01:24:47 UTC
[arrow] branch master updated: ARROW-6082: [Python] check type of
the index_type passed to pa.dictionary()
This is an automated email from the ASF dual-hosted git repository.
wesm 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 c675df4 ARROW-6082: [Python] check type of the index_type passed to pa.dictionary()
c675df4 is described below
commit c675df49e0fbbc9e81a2ddcfe8699a17fec22a0f
Author: Joris Van den Bossche <jo...@gmail.com>
AuthorDate: Thu Aug 8 20:24:33 2019 -0500
ARROW-6082: [Python] check type of the index_type passed to pa.dictionary()
https://issues.apache.org/jira/browse/ARROW-6082
Closes #5041 from jorisvandenbossche/ARROW-6082-dictionary-crash and squashes the following commits:
c0d5f51db <Joris Van den Bossche> ARROW-6082: check type of the index_type passed to pa.dictionary()
Authored-by: Joris Van den Bossche <jo...@gmail.com>
Signed-off-by: Wes McKinney <we...@apache.org>
---
python/pyarrow/tests/test_types.py | 6 ++++++
python/pyarrow/types.pxi | 3 +++
2 files changed, 9 insertions(+)
diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index fb1437d..26ff268 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -357,6 +357,12 @@ def test_dictionary_type():
assert ty2.value_type == pa.string()
assert ty2.ordered is False
+ # invalid index type raises
+ with pytest.raises(TypeError):
+ pa.dictionary(pa.string(), pa.int64())
+ with pytest.raises(TypeError):
+ pa.dictionary(pa.uint32(), pa.string())
+
def test_types_hashable():
many_types = get_many_types()
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index 03a4b3d..7097f5b 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -1664,6 +1664,9 @@ cpdef DictionaryType dictionary(index_type, value_type, bint ordered=False):
DictionaryType out = DictionaryType.__new__(DictionaryType)
shared_ptr[CDataType] dict_type
+ if _index_type.id not in {Type_INT8, Type_INT16, Type_INT32, Type_INT64}:
+ raise TypeError("The dictionary index type should be signed integer.")
+
dict_type.reset(new CDictionaryType(_index_type.sp_type,
_value_type.sp_type, ordered == 1))
out.init(dict_type)