From 8b9bc1b141535c78ffea0fdd42f87d67d05ddbe9 Mon Sep 17 00:00:00 2001 From: Jayce Slesar <47452474+jayceslesar@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:13:15 -0500 Subject: [PATCH] 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 9cda219099..6b373b7b9d 100644 --- a/pyiceberg/transforms.py +++ b/pyiceberg/transforms.py @@ -262,7 +262,7 @@ def hash_func(v: Any) -> 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 8bec84445c..ed0c495a14 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),