diff --git a/src/parselmouth/praat.cpp b/src/parselmouth/praat.cpp index 9ad9a8ae..de712062 100644 --- a/src/parselmouth/praat.cpp +++ b/src/parselmouth/praat.cpp @@ -98,20 +98,23 @@ py::object autoSTRVECToArray(autoSTRVEC &&vector) { if (!vector.elements) return py::none(); - - auto v = vector.get(); // _stringvector - // return py::array_t(py::cast(std::vector(v.begin(), v.end()))); // fails with error: static assertion failed: Attempt to use a non-POD or unimplemented POD type as a numpy dtype - - // candidate #1: still the same error if casted, - // std::vector str_vec; - // std::transform(v.begin(), v.end(), std::back_inserter(str_vec), [](auto &s) - // { return std::u32string_view(s,std::char_traits::length(s)); }); - // return str_vec; - - py::list str_list(v.size); - for (int i=0;i(py::cast(std::vector(v.begin(), v.end()))); + + // candidate 1 - py::list->py::array - seems redundant + // py::list str_list(v.size); + // for (int i=0;i(str_array.mutable_data()); + for (int i = 0; i < v.size; ++i) + view[i] = py::cast(v[i + 1]); + return str_array; } class PraatEnvironment { diff --git a/tests/test_praat.py b/tests/test_praat.py index 0a34e01c..a1a321ff 100644 --- a/tests/test_praat.py +++ b/tests/test_praat.py @@ -143,8 +143,8 @@ def test_call_return_string_vector(): strings_vector = parselmouth.praat.call(strings, "List all strings") assert isinstance(strings_vector, np.ndarray) assert strings_vector.shape == (5,) - # assert strings_vector.dtype == np.object_ - assert strings_vector.dtype == np.dtype('