You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2017/11/12 14:16:42 UTC

[arrow] branch master updated: ARROW-1763: [Python] Implement __hash__ for DataType

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

uwe 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 7adadd8  ARROW-1763: [Python] Implement __hash__ for DataType
7adadd8 is described below

commit 7adadd8e0c2f693d7c862e36162e1342dff20926
Author: Wes McKinney <we...@twosigma.com>
AuthorDate: Sun Nov 12 15:16:35 2017 +0100

    ARROW-1763: [Python] Implement __hash__ for DataType
    
    Author: Wes McKinney <we...@twosigma.com>
    
    Closes #1308 from wesm/ARROW-1763 and squashes the following commits:
    
    4e379b9 [Wes McKinney] Implement __hash__ for DataType
---
 python/pyarrow/tests/test_types.py | 24 ++++++++++++++++++++++++
 python/pyarrow/types.pxi           |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py
index 0e3ea1f..9eefa33 100644
--- a/python/pyarrow/tests/test_types.py
+++ b/python/pyarrow/tests/test_types.py
@@ -137,3 +137,27 @@ def test_is_temporal_date_time_timestamp():
 def test_timestamp_type():
     # See ARROW-1683
     assert isinstance(pa.timestamp('ns'), pa.TimestampType)
+
+
+def test_types_hashable():
+    types = [
+        pa.null(),
+        pa.int32(),
+        pa.time32('s'),
+        pa.time64('us'),
+        pa.date32(),
+        pa.timestamp('us'),
+        pa.string(),
+        pa.binary(),
+        pa.binary(10),
+        pa.list_(pa.int32()),
+        pa.struct([pa.field('a', pa.int32()),
+                   pa.field('b', pa.int8()),
+                   pa.field('c', pa.string())])
+    ]
+
+    in_dict = {}
+    for i, type_ in enumerate(types):
+        assert hash(type_) == hash(type_)
+        in_dict[type_] = i
+        assert in_dict[type_] == i
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index d2e68ff..edf0d8a 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -69,6 +69,9 @@ cdef class DataType:
             )
         return frombytes(self.type.ToString())
 
+    def __hash__(self):
+        return hash(str(self))
+
     def __reduce__(self):
         return self.__class__, (), self.__getstate__()
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <co...@arrow.apache.org>'].