Skip to content

Commit 9b27065

Browse files
authored
ARROW-113 Treat nan as null when coercing to int (#152)
Remove pandas -0b1 << 63 workaround.
1 parent a3ba75c commit 9b27065

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.github/workflows/test-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
python -m pip install -v -e ".[test]"
8888
- name: Run the tests
8989
run: |
90-
PYTHONWARNINGS=error python -m pytest -vv
90+
PYTHONWARNINGS=error python -m pytest -s -vv
9191
- name: Check the manifest
9292
run: |
9393
pip install check-manifest

bindings/python/pymongoarrow/lib.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import copy
2121
import datetime
2222
import enum
2323
import sys
24+
from math import isnan
2425

2526
# Python imports
2627
import bson
@@ -269,9 +270,15 @@ cdef void process_raw_bson_stream(const uint8_t * docstream, size_t length, obje
269270
int64_builder = builder
270271
if (value_t == BSON_TYPE_INT64 or
271272
value_t == BSON_TYPE_BOOL or
272-
value_t == BSON_TYPE_DOUBLE or
273273
value_t == BSON_TYPE_INT32):
274274
int64_builder.append_raw(bson_iter_as_int64(&doc_iter))
275+
elif value_t == BSON_TYPE_DOUBLE:
276+
# Treat nan as null.
277+
val = bson_iter_as_double(&doc_iter)
278+
if isnan(val):
279+
int64_builder.append_null()
280+
else:
281+
int64_builder.append_raw(bson_iter_as_int64(&doc_iter))
275282
else:
276283
int64_builder.append_null()
277284
elif ftype == BSON_TYPE_OID:

bindings/python/test/test_pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def find_fn(self, coll, query, schema):
354354
return find_pandas_all(coll, query, schema=schema)
355355

356356
def equal_fn(self, left, right):
357-
left = left.fillna(0).replace(-0b1 << 63, 0) # NaN is sometimes this
358-
right = right.fillna(0).replace(-0b1 << 63, 0)
357+
left = left.fillna(0)
358+
right = right.fillna(0)
359359
if type(left) == pandas.DataFrame:
360360
pandas.testing.assert_frame_equal(left, right, check_dtype=False)
361361
else:

0 commit comments

Comments
 (0)