[ 
https://issues.apache.org/jira/browse/ARROW-2101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16437279#comment-16437279
 ] 

ASF GitHub Bot commented on ARROW-2101:
---------------------------------------

pitrou commented on a change in pull request #1886: Bug fix for ARROW-2101
URL: https://github.com/apache/arrow/pull/1886#discussion_r181381388
 
 

 ##########
 File path: python/pyarrow/tests/test_convert_numpy.py
 ##########
 @@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import numpy as np
+import pyarrow as pa
+
+import pytest
+
+# Regression test for ARROW-2101
+def test_convert_numpy_array_of_bytes_to_arrow_array_of_strings():
+    converted = pa.array(np.array([b'x'], dtype=object), pa.string())
+    assert converted.type == pa.string()
+
+# Make sure that if an ndarray of bytes is passed to the array
+# constructor and the type is string, it will fail if those bytes
+# cannot be converted to utf-8
+def test_convert_numpy_array_of_bytes_to_arrow_array_of_strings_bad_data():
+    with pytest.raises(pa.lib.ArrowException,
+                       message="Unknown error: 'utf-8' codec can't decode byte 
0x80 in position 0: invalid start byte"):
+        pa.array(np.array([b'\x80\x81'], dtype=object), pa.string())
 
 Review comment:
   Indeed. Also I don't think we need both Python and C++ tests. Given the 
difference in verbosity and maintainability, I'd favour writing the tests on 
the Python side.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Python] from_pandas reads 'str' type as binary Arrow data with Python 2
> ------------------------------------------------------------------------
>
>                 Key: ARROW-2101
>                 URL: https://issues.apache.org/jira/browse/ARROW-2101
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>    Affects Versions: 0.8.0
>            Reporter: Bryan Cutler
>            Assignee: Bryan Cutler
>            Priority: Major
>              Labels: pull-request-available
>
> Using Python 2, converting Pandas with 'str' data to Arrow results in Arrow 
> data of binary type, even if the user supplies type information.  conversion 
> of 'unicode' type works to create Arrow data of string types.  For example
> {code}
> In [25]: pa.Array.from_pandas(pd.Series(['a'])).type
> Out[25]: DataType(binary)
> In [26]: pa.Array.from_pandas(pd.Series(['a']), type=pa.string()).type
> Out[26]: DataType(binary)
> In [27]: pa.Array.from_pandas(pd.Series([u'a'])).type
> Out[27]: DataType(string)
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to