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

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 8b9bc1b  Fix divide by zero on Bucket Transform (#187)
8b9bc1b is described below

commit 8b9bc1b141535c78ffea0fdd42f87d67d05ddbe9
Author: Jayce Slesar <[email protected]>
AuthorDate: Wed Dec 6 16:13:15 2023 -0500

    Fix divide by zero on Bucket Transform (#187)
---
 pyiceberg/transforms.py  | 2 +-
 tests/test_transforms.py | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/pyiceberg/transforms.py b/pyiceberg/transforms.py
index 9cda219..6b373b7 100644
--- a/pyiceberg/transforms.py
+++ b/pyiceberg/transforms.py
@@ -262,7 +262,7 @@ class BucketTransform(Transform[S, int]):
             raise ValueError(f"Unknown type {source}")
 
         if bucket:
-            return lambda v: (hash_func(v) & IntegerType.max) % 
self._num_buckets if v else None
+            return lambda v: (hash_func(v) & IntegerType.max) % 
self._num_buckets if v is not None else None
         return hash_func
 
     def __repr__(self) -> str:
diff --git a/tests/test_transforms.py b/tests/test_transforms.py
index 8bec844..ed0c495 100644
--- a/tests/test_transforms.py
+++ b/tests/test_transforms.py
@@ -135,6 +135,7 @@ def test_bucket_hash_values(test_input: Any, test_type: 
PrimitiveType, expected:
 @pytest.mark.parametrize(
     "transform,value,expected",
     [
+        (BucketTransform(2).transform(IntegerType()), 0, 0),
         (BucketTransform(100).transform(IntegerType()), 34, 79),
         (BucketTransform(100).transform(LongType()), 34, 79),
         (BucketTransform(100).transform(DateType()), 17486, 26),

Reply via email to