Skip to content

[C++][Python] pyarrow.compute.field("x").isin([0.0]) incorrectly filters out all rows when they all match #46183

Open

Description

@ypsah

Describe the bug, including details regarding any error messages, version, and platform.

Hi,

In some (rather specific) situations, the following filter expression: pyarrow.compute.field("x").isin([0.0]) incorrectly filters out matching rows.

Here is a minimal reproducer:

from tempfile import TemporaryDirectory

import pyarrow.compute
import pyarrow.dataset
import pyarrow.parquet


data = pyarrow.table({"x": [0.0]})

f0 = pyarrow.compute.field("x") == 0.0
f1 = pyarrow.compute.field("x").isin([0.0])

with TemporaryDirectory() as tmpdir:
    pyarrow.parquet.write_to_dataset(data, tmpdir)

    assert data == pyarrow.dataset.dataset(tmpdir).to_table()
    assert data == pyarrow.dataset.dataset(tmpdir).filter(f0).to_table()
    assert data == (actual := pyarrow.dataset.dataset(tmpdir).filter(f1).to_table()), actual

Output:

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.

Component(s)

Python, C++

Activity

  1. ypsah commented on Apr 20, 2025

    @ypsah
    Author

    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.

  2. 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
  3. raulcd commented on Apr 28, 2025

    @raulcd
    Member

    The issue seems specific to dataset filtering:

    >>> pyarrow.dataset.dataset('test.parquet').filter(f1).to_table()
    pyarrow.Table
    x: double
    ----
    x: [[]]
    >>> pyarrow.dataset.dataset('test.parquet').to_table().filter(f1)
    pyarrow.Table
    x: double
    ----
    x: [[0]]
    >>> pyarrow.dataset.dataset('test.parquet').filter(f0).to_table()
    pyarrow.Table
    x: double
    ----
    x: [[0]]
  4. 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
  5. ypsah commented on Apr 28, 2025

    @ypsah
    Author

    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.

  6. ypsah commented on May 6, 2025

    @ypsah
    Author

    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:

    // XXX in the case of FP values, we'd like equal values to have the same hash,
    , the two don't compare equal. (Credit to @pitrou for leaving a helpful comment about it)

    I'm not sure how to proceed forward from this point on. Can someone from the community please advise?

  7. pitrou commented on May 7, 2025

    @pitrou
    Member

    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

  8. ypsah commented on Jun 3, 2025

    @ypsah
    Author

    Would it be agreeable if I simply special cased the hashing of the binary representation of -0.0 to match that 0.0?

  9. pitrou commented on Jun 3, 2025

    @pitrou
    Member

    Would it be agreeable if I simply special cased the hashing of the binary representation of -0.0 to match that 0.0?

    Yes, that should be sufficient. (unit tests should be added too, of course)

  10. added
    Status: confirmed
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: C++Component: PythonStatus: confirmedType: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions