From 30a49f2b1f40dbe6dcf21e7a4a90230c6496dab3 Mon Sep 17 00:00:00 2001 From: Yifan Date: Thu, 14 Oct 2021 13:07:36 +0900 Subject: [PATCH] Fix MemoryError in string operators (#159) --- pyshgp/push/types.py | 2 +- tests/push/test_stack.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyshgp/push/types.py b/pyshgp/push/types.py index 43fab84..e5a8a23 100644 --- a/pyshgp/push/types.py +++ b/pyshgp/push/types.py @@ -103,7 +103,7 @@ def __init__(self): class PushStrType(PushType): def __init__(self): - super().__init__("str", (str, np.str_, np.object_)) + super().__init__("str", (str, np.str_, np.object_), is_collection=True) class PushVectorType(PushType): diff --git a/tests/push/test_stack.py b/tests/push/test_stack.py index bf06e83..fb07350 100644 --- a/tests/push/test_stack.py +++ b/tests/push/test_stack.py @@ -65,3 +65,8 @@ def test_set_nth_oob(self, str_stack: PushStack): def test_flush(self, int_stack: PushStack): int_stack.push(1).push(-1).flush() assert len(int_stack) == 0 + + def test_large_str(self, str_stack: PushStack): + s = "largestr"*1000 + str_stack.push(s) + assert len(str_stack.pop()) != len(s)