1
+ import pytest
1
2
import datajoint as dj
2
3
import timeit
3
4
import numpy as np
10
11
from .schema import Longblob
11
12
12
13
14
+ @pytest .fixture
15
+ def enable_feature_32bit_dims ():
16
+ dj .blob .use_32bit_dims = True
17
+ yield
18
+ dj .blob .use_32bit_dims = False
19
+
20
+
13
21
def test_pack ():
14
22
for x in (
15
23
32 ,
@@ -180,6 +188,8 @@ def test_insert_longblob(schema_any):
180
188
assert (Longblob & "id=1" ).fetch1 ()["data" ].all () == query_mym_blob ["data" ].all ()
181
189
(Longblob & "id=1" ).delete ()
182
190
191
+
192
+ def test_insert_longblob_32bit (schema_any , enable_feature_32bit_dims ):
183
193
query_32_blob = (
184
194
"INSERT INTO djtest_test1.longblob (id, data) VALUES (1, "
185
195
"X'6D596D00530200000001000000010000000400000068697473007369646573007461736B73007374"
@@ -190,7 +200,6 @@ def test_insert_longblob(schema_any):
190
200
"00000041020000000100000008000000040000000000000053007400610067006500200031003000')"
191
201
)
192
202
dj .conn ().query (query_32_blob ).fetchall ()
193
- dj .blob .use_32bit_dims = True
194
203
fetched = (Longblob & "id=1" ).fetch1 ()
195
204
expected = {
196
205
"id" : 1 ,
@@ -211,25 +220,31 @@ def test_insert_longblob(schema_any):
211
220
assert fetched ["id" ] == expected ["id" ]
212
221
assert np .array_equal (fetched ["data" ], expected ["data" ])
213
222
(Longblob & "id=1" ).delete ()
214
- dj .blob .use_32bit_dims = False
215
223
216
224
217
225
def test_datetime_serialization_speed ():
218
226
# If this fails that means for some reason deserializing/serializing
219
227
# np arrays of np.datetime64 types is now slower than regular arrays of datetime
228
+ assert not dj .blob .use_32bit_dims , "32 bit dims should be off for this test"
229
+ context = dict (
230
+ np = np ,
231
+ datetime = datetime ,
232
+ pack = pack ,
233
+ unpack = unpack ,
234
+ )
220
235
221
236
optimized_exe_time = timeit .timeit (
222
237
setup = "myarr=pack(np.array([np.datetime64('2022-10-13 03:03:13') for _ in range(0, 10000)]))" ,
223
238
stmt = "unpack(myarr)" ,
224
239
number = 10 ,
225
- globals = globals () ,
240
+ globals = context ,
226
241
)
227
242
print (f"np time { optimized_exe_time } " )
228
243
baseline_exe_time = timeit .timeit (
229
244
setup = "myarr2=pack(np.array([datetime(2022,10,13,3,3,13) for _ in range (0, 10000)]))" ,
230
245
stmt = "unpack(myarr2)" ,
231
246
number = 10 ,
232
- globals = globals () ,
247
+ globals = context ,
233
248
)
234
249
print (f"python time { baseline_exe_time } " )
235
250
0 commit comments