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),