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 abb9341 ARROW-1905: [Python] Add more comprehensive list of exact type checking functions to pyarrow.types abb9341 is described below commit abb934176ff3424663bab40b62afcc0eacf4ad2b Author: Wes McKinney <wes.mckin...@twosigma.com> AuthorDate: Mon Dec 11 10:09:16 2017 -0500 ARROW-1905: [Python] Add more comprehensive list of exact type checking functions to pyarrow.types cc @BryanCutler Author: Wes McKinney <wes.mckin...@twosigma.com> Closes #1410 from wesm/ARROW-1905 and squashes the following commits: 93bddc9f [Wes McKinney] Add new functions to API, fix docstring dcd0829f [Wes McKinney] Add more exact type checking functions --- python/doc/source/api.rst | 15 +++++ python/pyarrow/tests/test_types.py | 23 ++++++++ python/pyarrow/types.py | 117 +++++++++++++++++++++++++++++++++++-- 3 files changed, 149 insertions(+), 6 deletions(-) diff --git a/python/doc/source/api.rst b/python/doc/source/api.rst index 636f41d..2d3e39c 100644 --- a/python/doc/source/api.rst +++ b/python/doc/source/api.rst @@ -71,7 +71,18 @@ Type checking functions is_integer is_signed_integer is_unsigned_integer + is_int8 + is_int16 + is_int32 + is_int64 + is_uint8 + is_uint16 + is_uint32 + is_uint64 is_floating + is_float16 + is_float32 + is_float64 is_decimal is_list is_struct @@ -80,7 +91,11 @@ Type checking functions is_temporal is_timestamp is_date + is_date32 + is_date64 is_time + is_time32 + is_time64 is_null is_binary is_unicode diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py index e352e35..68dc499 100644 --- a/python/pyarrow/tests/test_types.py +++ b/python/pyarrow/tests/test_types.py @@ -15,6 +15,8 @@ # specific language governing permissions and limitations # under the License. +import pytest + import pyarrow as pa import pyarrow.types as types @@ -161,3 +163,24 @@ def test_types_hashable(): assert hash(type_) == hash(type_) in_dict[type_] = i assert in_dict[type_] == i + + +@pytest.mark.parametrize('t,check_func', [ + (pa.date32(), types.is_date32), + (pa.date64(), types.is_date64), + (pa.time32('s'), types.is_time32), + (pa.time64('ns'), types.is_time64), + (pa.int8(), types.is_int8), + (pa.int16(), types.is_int16), + (pa.int32(), types.is_int32), + (pa.int64(), types.is_int64), + (pa.uint8(), types.is_uint8), + (pa.uint16(), types.is_uint16), + (pa.uint32(), types.is_uint32), + (pa.uint64(), types.is_uint64), + (pa.float16(), types.is_float16), + (pa.float32(), types.is_float32), + (pa.float64(), types.is_float64) +]) +def test_exact_primitive_types(t, check_func): + assert check_func(t) diff --git a/python/pyarrow/types.py b/python/pyarrow/types.py index 440d7eb..2455714 100644 --- a/python/pyarrow/types.py +++ b/python/pyarrow/types.py @@ -32,6 +32,13 @@ _TEMPORAL_TYPES = {lib.Type_TIMESTAMP} | _TIME_TYPES | _DATE_TYPES _NESTED_TYPES = {lib.Type_LIST, lib.Type_STRUCT, lib.Type_UNION, lib.Type_MAP} +def is_null(t): + """ + Return True if value is an instance of a null type + """ + return t.id == lib.Type_NA + + def is_boolean(t): """ Return True if value is an instance of a boolean type @@ -41,25 +48,81 @@ def is_boolean(t): def is_integer(t): """ - Return True if value is an instance of an integer type + Return True if value is an instance of any integer type """ return t.id in _INTEGER_TYPES def is_signed_integer(t): """ - Return True if value is an instance of a signed integer type + Return True if value is an instance of any signed integer type """ return t.id in _SIGNED_INTEGER_TYPES def is_unsigned_integer(t): """ - Return True if value is an instance of an unsigned integer type + Return True if value is an instance of any unsigned integer type """ return t.id in _UNSIGNED_INTEGER_TYPES +def is_int8(t): + """ + Return True if value is an instance of an int8 type + """ + return t.id == lib.Type_INT8 + + +def is_int16(t): + """ + Return True if value is an instance of an int16 type + """ + return t.id == lib.Type_INT16 + + +def is_int32(t): + """ + Return True if value is an instance of an int32 type + """ + return t.id == lib.Type_INT32 + + +def is_int64(t): + """ + Return True if value is an instance of an int64 type + """ + return t.id == lib.Type_INT64 + + +def is_uint8(t): + """ + Return True if value is an instance of an uint8 type + """ + return t.id == lib.Type_UINT8 + + +def is_uint16(t): + """ + Return True if value is an instance of an uint16 type + """ + return t.id == lib.Type_UINT16 + + +def is_uint32(t): + """ + Return True if value is an instance of an uint32 type + """ + return t.id == lib.Type_UINT32 + + +def is_uint64(t): + """ + Return True if value is an instance of an uint64 type + """ + return t.id == lib.Type_UINT64 + + def is_floating(t): """ Return True if value is an instance of a floating point numeric type @@ -67,6 +130,27 @@ def is_floating(t): return t.id in _FLOATING_TYPES +def is_float16(t): + """ + Return True if value is an instance of an float16 (half-precision) type + """ + return t.id == lib.Type_HALF_FLOAT + + +def is_float32(t): + """ + Return True if value is an instance of an float32 (single precision) type + """ + return t.id == lib.Type_FLOAT + + +def is_float64(t): + """ + Return True if value is an instance of an float64 (double precision) type + """ + return t.id == lib.Type_DOUBLE + + def is_list(t): """ Return True if value is an instance of a list type @@ -117,11 +201,18 @@ def is_time(t): return t.id in _TIME_TYPES -def is_null(t): +def is_time32(t): """ - Return True if value is an instance of a null type + Return True if value is an instance of a time32 type """ - return t.id == lib.Type_NA + return t.id == lib.Type_TIME32 + + +def is_time64(t): + """ + Return True if value is an instance of a time64 type + """ + return t.id == lib.Type_TIME64 def is_binary(t): @@ -159,6 +250,20 @@ def is_date(t): return t.id in _DATE_TYPES +def is_date32(t): + """ + Return True if value is an instance of a date32 (days) type + """ + return t.id == lib.Type_DATE32 + + +def is_date64(t): + """ + Return True if value is an instance of a date64 (milliseconds) type + """ + return t.id == lib.Type_DATE64 + + def is_map(t): """ Return True if value is an instance of a map logical type -- To stop receiving notification emails like this one, please contact ['"commits@arrow.apache.org" <commits@arrow.apache.org>'].