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 6156b1d ARROW-640: [Python] Implement __hash__ and equality for Array
scalar values Arrow scalar values
6156b1d is described below
commit 6156b1d2169ba540bb89de05f9840c5a8c4a945f
Author: Alex <[email protected]>
AuthorDate: Mon Mar 26 17:54:34 2018 -0400
ARROW-640: [Python] Implement __hash__ and equality for Array scalar values
Arrow scalar values
Author: Alex <[email protected]>
Closes #1765 from AlexHagerman/master and squashes the following commits:
6e57dcba <Alex> Merge set tests.
1b1c2c57 <Alex> Removed int_eq test based on feedback and test_int64.
Removed type check on __hash__. Corrected hash tests.
4497b69d <Alex> Formatted per flake8 guidelines. Added asset to validate
set conversion from array.
309109db <Alex> Removed unused import of number.
75f98201 <Alex> Added __hash__ for scalar ints per Arrow JIRA ticket #640.
---
python/pyarrow/scalar.pxi | 2 ++
python/pyarrow/tests/test_scalars.py | 27 +++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/python/pyarrow/scalar.pxi b/python/pyarrow/scalar.pxi
index e9c2c7c..eb8bb25 100644
--- a/python/pyarrow/scalar.pxi
+++ b/python/pyarrow/scalar.pxi
@@ -73,6 +73,8 @@ cdef class ArrayValue(Scalar):
raise NotImplementedError(
"Cannot compare Arrow values that don't support as_py()")
+ def __hash__(self):
+ return hash(self.as_py())
cdef class BooleanValue(ArrayValue):
diff --git a/python/pyarrow/tests/test_scalars.py
b/python/pyarrow/tests/test_scalars.py
index c63be02..23dd237 100644
--- a/python/pyarrow/tests/test_scalars.py
+++ b/python/pyarrow/tests/test_scalars.py
@@ -177,3 +177,30 @@ class TestScalars(unittest.TestCase):
categorical.categories)
for i, c in enumerate(values):
assert v[i].as_py() == c
+
+ def test_int_hash(self):
+ # ARROW-640
+ int_arr = pa.array([1, 1, 2, 1])
+ assert hash(int_arr[0]) == hash(1)
+
+ def test_float_hash(self):
+ # ARROW-640
+ float_arr = pa.array([1.4, 1.2, 2.5, 1.8])
+ assert hash(float_arr[0]) == hash(1.4)
+
+ def test_string_hash(self):
+ # ARROW-640
+ str_arr = pa.array(["foo", "bar"])
+ assert hash(str_arr[1]) == hash("bar")
+
+ def test_bytes_hash(self):
+ # ARROW-640
+ byte_arr = pa.array([b'foo', None, b'bar'])
+ assert hash(byte_arr[2]) == hash(b"bar")
+
+ def test_array_to_set(self):
+ # ARROW-640
+ arr = pa.array([1, 1, 2, 1])
+ set_from_array = set(arr)
+ assert isinstance(set_from_array, set)
+ assert set_from_array == {1, 2}
--
To stop receiving notification emails like this one, please contact
[email protected].