[ 
https://issues.apache.org/jira/browse/ARROW-1905?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16286018#comment-16286018
 ] 

ASF GitHub Bot commented on ARROW-1905:
---------------------------------------

wesm closed pull request #1410: ARROW-1905: [Python] Add more comprehensive 
list of exact type checking functions to pyarrow.types
URL: https://github.com/apache/arrow/pull/1410
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/python/doc/source/api.rst b/python/doc/source/api.rst
index 636f41d67..2d3e39c69 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 e352e35a3..68dc499cf 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
+
+
[email protected]('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 440d7eb09..24557148a 100644
--- a/python/pyarrow/types.py
+++ b/python/pyarrow/types.py
@@ -32,6 +32,13 @@
 _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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [Python] Add more functions for checking exact types in pyarrow.types
> ---------------------------------------------------------------------
>
>                 Key: ARROW-1905
>                 URL: https://issues.apache.org/jira/browse/ARROW-1905
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Python
>            Reporter: Wes McKinney
>            Assignee: Wes McKinney
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> In https://github.com/apache/arrow/blob/master/python/pyarrow/types.py, we 
> can check {{pyarrow.is_date}} but not whether something is date32 or date64. 
> See discussion in 
> https://github.com/apache/spark/pull/19884#discussion_r155626249



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to