File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ new_stringdtype_instance(void)
19
19
new -> base .elsize = sizeof (ss * );
20
20
new -> base .alignment = _Alignof(ss * );
21
21
new -> base .flags |= NPY_NEEDS_INIT ;
22
+ new -> base .flags |= NPY_LIST_PICKLE ;
22
23
23
24
return new ;
24
25
}
Original file line number Diff line number Diff line change
1
+ import concurrent .futures
1
2
import os
2
3
import pickle
3
4
import tempfile
@@ -129,15 +130,34 @@ def test_memory_usage(string_list):
129
130
_memory_usage (np .array ([1 , 2 , 3 ]))
130
131
131
132
132
- def test_pickle_dtype ():
133
+ def _pickle_load (filename ):
134
+ with open (filename , "rb" ) as f :
135
+ res = pickle .load (f )
136
+
137
+ return res
138
+
139
+
140
+ def test_pickle (string_list ):
133
141
dtype = StringDType ()
134
142
143
+ arr = np .array (string_list , dtype = dtype )
144
+
135
145
with tempfile .NamedTemporaryFile ("wb" , delete = False ) as f :
136
- pickle .dump (dtype , f )
146
+ pickle .dump ([ arr , dtype ] , f )
137
147
138
148
with open (f .name , "rb" ) as f :
139
- load_dtype = pickle .load (f )
149
+ res = pickle .load (f )
150
+
151
+ np .testing .assert_array_equal (res [0 ], arr )
152
+ assert res [1 ] == dtype
153
+
154
+ # load the pickle in a subprocess to ensure the string data are
155
+ # actually stored in the pickle file
156
+ with concurrent .futures .ProcessPoolExecutor () as executor :
157
+ e = executor .submit (_pickle_load , f .name )
158
+ res = e .result ()
140
159
141
- assert dtype == load_dtype
160
+ np .testing .assert_array_equal (res [0 ], arr )
161
+ assert res [1 ] == dtype
142
162
143
163
os .remove (f .name )
You can’t perform that action at this time.
0 commit comments