Skip to content

Commit e8aee2f

Browse files
committed
test: add test that NaNs in pyarrow tables roundtrip
1 parent d7083c2 commit e8aee2f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import annotations
2+
3+
import math
4+
5+
import pytest
6+
7+
import ibis
8+
9+
pa = pytest.importorskip("pyarrow")
10+
11+
12+
@pytest.mark.notimpl(
13+
"sqlite",
14+
"During memtable registration, the pa.Table is converted to a pandas DataFrame, losing NaN info",
15+
)
16+
@pytest.mark.parametrize(
17+
"method",
18+
[
19+
pytest.param(lambda pa_arr: pa.table({"f": pa_arr}), id="pa_table"),
20+
pytest.param(
21+
lambda pa_arr: {"f": pa_arr},
22+
id="dict_of_pa_arrays",
23+
marks=pytest.mark.xfail(
24+
# https://github.com/ibis-project/ibis/issues/11700
25+
reason="During ops.InMemoryTable creation, we go through pd.DataFrame, losing NaN info"
26+
),
27+
),
28+
],
29+
)
30+
def test_nans_roundtrip(con, method):
31+
inp = [1.0, float("nan"), None]
32+
t = ibis.memtable(method(pa.array(inp)))
33+
34+
def make_comparable(vals):
35+
return {"nan" if (isinstance(v, float) and math.isnan(v)) else v for v in vals}
36+
37+
result = make_comparable(con.to_pyarrow(t.f).to_pylist())
38+
expected = make_comparable(inp)
39+
assert result == expected

0 commit comments

Comments
 (0)