bug: `join` on `float("nan")` behaves differently
Spotted in https://github.com/narwhals-dev/narwhals/actions/runs/24605500399/job/71950954205?pr=3552
Repro:
def test_inner_join_nan(constructor: Constructor) -> None:
data = {
"a": [0, 0, 0],
"b": [0, 0, 0],
"c": [0.0, 0.0, float("nan")],
}
join_cols = ["a", "c"]
frame = from_native_lazy(constructor(data))
result = frame.join(frame, on=join_cols, how="inner").sort("c", nulls_last=True).collect()
zero_cols = ("a", "b", "b_right")
for col in zero_cols:
assert (result.get_column(col)==0).all()
assert (result.get_column("c").is_nan().sum())==1
# NOTE: polars results in the following:
"""
expected = {
"a": [0, 0, 0, 0, 0],
"b": [0, 0, 0, 0, 0],
"c": [0., 0., 0., 0., float("nan")],
"b_right": [0, 0, 0, 0, 0],
}
How can we sort the data to use:
assert_equal_data(result, expected)
"""
will result in failures for (any) pandas like, dask, and duckdb
$ pytest tests/frame/join_test.py -k inner_join_nan --all-cpu-constructors
FAILED tests/frame/join_test.py::test_inner_join_nan[pandas] - AssertionError: assert np.int64(0) == 1
FAILED tests/frame/join_test.py::test_inner_join_nan[pandas[nullable]] - AssertionError: assert np.int64(0) == 1
FAILED tests/frame/join_test.py::test_inner_join_nan[modin[pyarrow]] - AssertionError: assert 0 == 1
FAILED tests/frame/join_test.py::test_inner_join_nan[pandas[pyarrow]] - AssertionError: assert 0 == 1
FAILED tests/frame/join_test.py::test_inner_join_nan[duckdb] - AssertionError: assert 0 == 1
FAILED tests/frame/join_test.py::test_inner_join_nan[dask] - AssertionError: assert np.int64(0) == 1
I think for:
- pandas-like nullable (and maybe dask pyarrow backed?) we should be able to pass such test (eventually)
- duckdb definitely we can (#3555 )
Hi @FBruzzesi ,
I’m interested in investigating this issue. I’ll start by reproducing the failing cases and checking the pandas-like backend behavior first, since DuckDB seems to already have a related fix in #3555.
If this is still available, I’d be happy to work on a focused PR for one backend or a small test improvement.
Thank you!
Hi @sriharan0804 👋🏼 thanks for your interest in the issue.
since DuckDB seems to already have a related fix in https://github.com/narwhals-dev/narwhals/pull/3555.
Such PR was reverted, due to the issue mentioned in https://github.com/narwhals-dev/narwhals/pull/3555#issuecomment-4466153235
I would suggest to first try to address the duckdb case by checking the columns dtype after collecting the frame schemas. I expect pandas to be much more of a headache!