You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2019/06/25 10:13:45 UTC

[arrow] branch master updated: ARROW-2298: [Python] Add unit tests to assert that float64 with NaN values can be safely coerced to integer types when converting from pandas

This is an automated email from the ASF dual-hosted git repository.

kszucs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new b72544f  ARROW-2298: [Python] Add unit tests to assert that float64 with NaN values can be safely coerced to integer types when converting from pandas
b72544f is described below

commit b72544fa4696fb37e229b8727a670dae3d1c6c1d
Author: Wes McKinney <we...@apache.org>
AuthorDate: Tue Jun 25 12:13:35 2019 +0200

    ARROW-2298: [Python] Add unit tests to assert that float64 with NaN values 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 <we...@apache.org>
    
    Closes #4682 from wesm/ARROW-2298 and squashes the following commits:
    
    33d485e90 <Wes McKinney> Add unit tests to assert desired behavior according to JIRA issue
---
 python/pyarrow/tests/test_pandas.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/python/pyarrow/tests/test_pandas.py b/python/pyarrow/tests/test_pandas.py
index 3cc04dc..33b35da 100644
--- a/python/pyarrow/tests/test_pandas.py
+++ b/python/pyarrow/tests/test_pandas.py
@@ -767,6 +767,23 @@ class TestConvertPrimitiveTypes(object):
         _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})