Skip to content

Commit 3489135

Browse files
authored
Merge pull request #50 from ngoldbaum/fix-string-cast
Fix string-to-string cast when the output array is non-null
2 parents 6e04b14 + fac6501 commit 3489135

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

stringdtype/stringdtype/src/casts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ string_to_string(PyArrayMethod_Context *NPY_UNUSED(context),
5757
while (N--) {
5858
load_string(in, &s);
5959
os = (ss *)out;
60+
ssfree(os);
6061
if (ssdup(s, os) < 0) {
6162
gil_error(PyExc_MemoryError, "ssdup failed");
6263
return -1;

stringdtype/tests/test_stringdtype.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,16 @@ def test_bool_cast(string_list, cast_answer, any_answer, all_answer):
261261

262262
assert np.any(sarr) == any_answer
263263
assert np.all(sarr) == all_answer
264+
265+
266+
def test_take(string_list):
267+
sarr = np.array(string_list, dtype=StringDType())
268+
out = np.empty(len(string_list), dtype=StringDType())
269+
res = sarr.take(np.arange(len(string_list)), out=out)
270+
np.testing.assert_array_equal(sarr, res)
271+
np.testing.assert_array_equal(res, out)
272+
273+
# make sure it also works for out that isn't empty
274+
out[0] = "hello"
275+
res = sarr.take(np.arange(len(string_list)), out=out)
276+
np.testing.assert_array_equal(res, out)

0 commit comments

Comments
 (0)