ngoldbaum commented on code in PR #50951:
URL: https://github.com/apache/arrow/pull/50951#discussion_r3857063252
##########
python/pyarrow/tests/test_array.py:
##########
@@ -2925,6 +2925,85 @@ def test_array_from_numpy_unicode(string_type):
assert arrow_arr.equals(expected)
[email protected]
+def numpy_string_dtype():
+ dtypes = pytest.importorskip("numpy.dtypes")
+ return dtypes.StringDType
+
+
[email protected]
[email protected]('string_type', [
+ None,
+ pa.string(),
+ pa.large_string(),
+ pa.string_view()])
+def test_array_from_numpy_string_dtype(numpy_string_dtype, string_type):
+ values = [
+ "short",
+ "a" * 100,
+ "b" * 300,
+ "árvíztűrő tükörfúrógép 🥐 你好",
+ "🥐" * 200,
+ "",
+ ]
+ arr = np.array(values, dtype=numpy_string_dtype())
+
+ arrow_arr = pa.array(arr, type=string_type)
+
+ arrow_arr.validate(full=True)
+ assert arrow_arr.type == (string_type or pa.string())
+ assert arrow_arr.to_pylist() == arr.tolist()
+
+ for sliced in (arr[:0], arr[::2], arr[::-1]):
+ arrow_arr = pa.array(sliced, type=string_type)
+ arrow_arr.validate(full=True)
+ assert arrow_arr.to_pylist() == sliced.tolist()
+
+
[email protected]
[email protected]('string_type', [
+ None,
+ pa.large_string(),
+ pa.string_view(),
+])
[email protected]('na_object', [None, "__placeholder__", float("nan")])
+def test_array_from_numpy_string_dtype_nulls_and_mask(
+ numpy_string_dtype, string_type, na_object):
+ arr = np.array(["some", na_object, "strings"],
+ dtype=numpy_string_dtype(na_object=na_object))
+
+ arrow_arr = pa.array(arr, type=string_type)
+ arrow_arr.validate(full=True)
+ assert arrow_arr.to_pylist() == ["some", None, "strings"]
Review Comment:
Why is the output missing sentinel `None` for all input `na_object` choices,
in particular for strings?
Note that this also disagrees with NumPy:
```
>>> np.array(["hello", "__placeholder__", "world"], dtype="T").tolist()
['hello', '__placeholder__', 'world']
```
Is there a reason why you can't more faithfully translate NumPy's string
missing data semantics?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]