Skip to content

Commit

Permalink
ARROW-2298: [Python] Add unit tests to assert that float64 with NaN v…
Browse files Browse the repository at this point in the history
…alues can be safely coerced to integer types when converting from pandas

This code used to fail in the past, but it has been fixed sometime since the issue was reported back in October 2018. This test case asserts the correct behavior so it can be maintained.

Author: Wes McKinney <[email protected]>

Closes #4682 from wesm/ARROW-2298 and squashes the following commits:

33d485e <Wes McKinney> Add unit tests to assert desired behavior according to JIRA issue
  • Loading branch information
wesm authored and kszucs committed Jun 25, 2019
1 parent c9290cb commit b72544f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,23 @@ def test_float_object_nulls(self):
_check_pandas_roundtrip(df, expected=expected,
expected_schema=schema)

def test_float_with_null_as_integer(self):
# ARROW-2298
s = pd.Series([np.nan, 1., 2., np.nan])

types = [pa.int8(), pa.int16(), pa.int32(), pa.int64(),
pa.uint8(), pa.uint16(), pa.uint32(), pa.uint64()]
for ty in types:
result = pa.array(s, type=ty)
expected = pa.array([None, 1, 2, None], type=ty)
assert result.equals(expected)

df = pd.DataFrame({'has_nulls': s})
schema = pa.schema([pa.field('has_nulls', ty)])
result = pa.Table.from_pandas(df, schema=schema,
preserve_index=False)
assert result[0].data.chunk(0).equals(expected)

def test_int_object_nulls(self):
arr = np.array([None, 1, np.int64(3)] * 5, dtype=object)
df = pd.DataFrame({'ints': arr})
Expand Down

0 comments on commit b72544f

Please sign in to comment.