You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++][Python] pyarrow.compute.field("x").isin([0.0]) incorrectly filters out all rows when they all match #46183
Traceback (most recent call last):
File "/tmp/tmp.iectDMOJmW/test.py", line 18, in <module>
assert data == (actual := pyarrow.dataset.dataset(tmpdir).filter(f1).to_table()), actual
AssertionError: pyarrow.Table
x: double
----
x: [[]]
This does not happen if x contains other values that are not 0.0 ( pyarrow.table({"x": [0.0, 1.0]}) --> ✅ | pyarrow.table({"x": [0.0, 0.0, 0.0]}) --> 💥).
I am able to reproduce this bug for all released versions since v12.
While the bug appears to have existed for numerous versions and its impact must have been limited until now, apache/iceberg-python's particular usage of pyarrow makes it a more concrete issue now: there, partitioned datasets include the partition columns (making it more likely that a whole fragment includes only 0.0).
This is how I initially encountered this issue, and mistakenly attributed it to apache/iceberg-python: apache/iceberg-python#1937.
changed the title [-]pyarrow.compute.field("x").isin(0.0) incorrectly filters out all rows when they all match[/-][+][C++][Python] pyarrow.compute.field("x").isin(0.0) incorrectly filters out all rows when they all match[/+]on Apr 28, 2025
changed the title [-][C++][Python] pyarrow.compute.field("x").isin(0.0) incorrectly filters out all rows when they all match[/-][+][C++][Python] pyarrow.compute.field("x").isin([0.0]) incorrectly filters out all rows when they all match[/+]on Apr 28, 2025
Correct, and I have been able to reproduce it in C++ today. I will try to find the root cause, but my C++ skills are basically non-existent, so any help is welcome.
I think I've got it: somehow, when the table only contains 0.0, those zeros get serialized as -0 the negative zero of the IEEE 754 standard, which has a different binary representation (0x3ff0000000000000) compared to the positive zero (0x0).
Since the hash function we use for set lookup hashes the binary representation of the value:
Well, we certainly want to fix the hashing function for floating-point values. There's the same problem in our other hash table (swiss table) implementation by the way. @zanmato1984
Activity
ypsah commentedon Apr 20, 2025
While the bug appears to have existed for numerous versions and its impact must have been limited until now, apache/iceberg-python's particular usage of
pyarrowmakes it a more concrete issue now: there, partitioned datasets include the partition columns (making it more likely that a whole fragment includes only0.0).This is how I initially encountered this issue, and mistakenly attributed it to
apache/iceberg-python: apache/iceberg-python#1937.[-]pyarrow.compute.field("x").isin(0.0) incorrectly filters out all rows when they all match[/-][+][C++][Python] pyarrow.compute.field("x").isin(0.0) incorrectly filters out all rows when they all match[/+]raulcd commentedon Apr 28, 2025
The issue seems specific to
datasetfiltering:[-][C++][Python] pyarrow.compute.field("x").isin(0.0) incorrectly filters out all rows when they all match[/-][+][C++][Python] pyarrow.compute.field("x").isin([0.0]) incorrectly filters out all rows when they all match[/+]ypsah commentedon Apr 28, 2025
Correct, and I have been able to reproduce it in C++ today. I will try to find the root cause, but my C++ skills are basically non-existent, so any help is welcome.
ypsah commentedon May 6, 2025
I think I've got it: somehow, when the table only contains
0.0, those zeros get serialized as-0the negative zero of the IEEE 754 standard, which has a different binary representation (0x3ff0000000000000) compared to the positive zero (0x0).Since the hash function we use for set lookup hashes the binary representation of the value:
arrow/cpp/src/arrow/util/hashing.h
Line 91 in f270643
I'm not sure how to proceed forward from this point on. Can someone from the community please advise?
pitrou commentedon May 7, 2025
Well, we certainly want to fix the hashing function for floating-point values. There's the same problem in our other hash table (swiss table) implementation by the way. @zanmato1984
ypsah commentedon Jun 3, 2025
Would it be agreeable if I simply special cased the hashing of the binary representation of -0.0 to match that 0.0?
pitrou commentedon Jun 3, 2025
Yes, that should be sufficient. (unit tests should be added too, of course)