Skip to content

Commit

Permalink
Fix divide by zero on Bucket Transform (apache#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayceslesar authored Dec 6, 2023
1 parent a368bd9 commit 8b9bc1b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyiceberg/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 8b9bc1b

Please sign in to comment.