Skip to content

Commit 15592e9

Browse files
committed
small updates.
1 parent 1f57fd8 commit 15592e9

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Release notes
22

3-
### 0.13.7 -- TBD
4-
* Bugfix - Fix networkx incompatable change by version pinning to 2.8.3 PR #1036 (#1035)
3+
### 0.13.7 -- Jul 13, 2022
4+
* Bugfix - Fix networkx incompatable change by version pinning to 2.6.3 PR #1036 (#1035)
55
* Add - Support for serializing numpy datetime64 types PR #1036 (#1022)
66
* Update - Add traceback to default logging PR #1036
77

datajoint/blob.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
14: {"dtype": np.dtype("int64"), "scalar_type": "INT64"},
3333
15: {"dtype": np.dtype("uint64"), "scalar_type": "UINT64"},
3434
16: {"dtype": None, "scalar_type": "FUNCTION"},
35-
65536: {"dtype": np.dtype("datetime64[Y]"), "scalar_type": "DATETIME64[Y]"},
36-
65537: {"dtype": np.dtype("datetime64[M]"), "scalar_type": "DATETIME64[M]"},
37-
65538: {"dtype": np.dtype("datetime64[W]"), "scalar_type": "DATETIME64[W]"},
38-
65539: {"dtype": np.dtype("datetime64[D]"), "scalar_type": "DATETIME64[D]"},
39-
65540: {"dtype": np.dtype("datetime64[h]"), "scalar_type": "DATETIME64[h]"},
40-
65541: {"dtype": np.dtype("datetime64[m]"), "scalar_type": "DATETIME64[m]"},
41-
65542: {"dtype": np.dtype("datetime64[s]"), "scalar_type": "DATETIME64[s]"},
42-
65543: {"dtype": np.dtype("datetime64[ms]"), "scalar_type": "DATETIME64[ms]"},
43-
65544: {"dtype": np.dtype("datetime64[us]"), "scalar_type": "DATETIME64[us]"},
44-
65545: {"dtype": np.dtype("datetime64[ns]"), "scalar_type": "DATETIME64[ns]"},
45-
65546: {"dtype": np.dtype("datetime64[ps]"), "scalar_type": "DATETIME64[ps]"},
46-
65547: {"dtype": np.dtype("datetime64[fs]"), "scalar_type": "DATETIME64[fs]"},
47-
65548: {"dtype": np.dtype("datetime64[as]"), "scalar_type": "DATETIME64[as]"},
35+
65_536: {"dtype": np.dtype("datetime64[Y]"), "scalar_type": "DATETIME64[Y]"},
36+
65_537: {"dtype": np.dtype("datetime64[M]"), "scalar_type": "DATETIME64[M]"},
37+
65_538: {"dtype": np.dtype("datetime64[W]"), "scalar_type": "DATETIME64[W]"},
38+
65_539: {"dtype": np.dtype("datetime64[D]"), "scalar_type": "DATETIME64[D]"},
39+
65_540: {"dtype": np.dtype("datetime64[h]"), "scalar_type": "DATETIME64[h]"},
40+
65_541: {"dtype": np.dtype("datetime64[m]"), "scalar_type": "DATETIME64[m]"},
41+
65_542: {"dtype": np.dtype("datetime64[s]"), "scalar_type": "DATETIME64[s]"},
42+
65_543: {"dtype": np.dtype("datetime64[ms]"), "scalar_type": "DATETIME64[ms]"},
43+
65_544: {"dtype": np.dtype("datetime64[us]"), "scalar_type": "DATETIME64[us]"},
44+
65_545: {"dtype": np.dtype("datetime64[ns]"), "scalar_type": "DATETIME64[ns]"},
45+
65_546: {"dtype": np.dtype("datetime64[ps]"), "scalar_type": "DATETIME64[ps]"},
46+
65_547: {"dtype": np.dtype("datetime64[fs]"), "scalar_type": "DATETIME64[fs]"},
47+
65_548: {"dtype": np.dtype("datetime64[as]"), "scalar_type": "DATETIME64[as]"},
4848
}
4949
serialize_lookup = {
5050
v["dtype"]: {"type_id": k, "scalar_type": v["scalar_type"]}
@@ -269,14 +269,13 @@ def pack_array(self, array):
269269
try:
270270
type_id = serialize_lookup[array.dtype]["type_id"]
271271
except KeyError:
272+
# U is for unicode string
272273
if array.dtype.char == "U":
273274
type_id = serialize_lookup[np.dtype("O")]["type_id"]
274-
pass
275275
else:
276-
raise DataJointError("Type %s is ambiguous or unknown" % array.dtype)
276+
raise DataJointError(f"Type {array.dtype} is ambiguous or unknown")
277277

278278
blob += np.array([type_id, is_complex], dtype=np.uint32).tobytes()
279-
# array of dtype('O'), U is for unicode string
280279
if (
281280
array.dtype.char == "U"
282281
or serialize_lookup[array.dtype]["scalar_type"] == "VOID"
@@ -286,7 +285,6 @@ def pack_array(self, array):
286285
for it in (self.pack_blob(e) for e in array.flatten(order="F"))
287286
)
288287
self.set_dj0() # not supported by original mym
289-
# array of dtype('c')
290288
elif serialize_lookup[array.dtype]["scalar_type"] == "CHAR":
291289
blob += (
292290
array.view(np.uint8).astype(np.uint16).tobytes()

docs-parts/intro/Releases_lang1.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
0.13.7 -- TBD
2-
--------------
3-
* Bugfix - Fix networkx incompatable change by version pinning to 2.8.3 PR #1036 (#1035)
1+
0.13.7 -- Jul 13, 2022
2+
----------------------
3+
* Bugfix - Fix networkx incompatable change by version pinning to 2.6.3 PR #1036 (#1035)
44
* Add - Support for serializing numpy datetime64 types PR #1036 (#1022)
55
* Update - Add traceback to default logging PR #1036
66

tests/test_blob.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import timeit
33
import numpy as np
44
import uuid
5+
from faker import Faker
56
from . import schema
67
from decimal import Decimal
78
from datetime import datetime
@@ -232,17 +233,17 @@ def test_datetime_serialization_speed():
232233
# If this fails that means for some reason deserializing/serializing
233234
# np arrays of np.datetime64 types is now slower than regular arrays of datetime64
234235

235-
np_array_dt_exe_time = timeit.timeit(
236-
setup="myarr=pack(np.array([np.datetime64(f'{x}') for x in range(1900, 2000)]))",
236+
optimized_exe_time = timeit.timeit(
237+
setup="myarr=pack(np.array([np.datetime64('2022-10-13 03:03:13') for _ in range(0, 10000)]))",
237238
stmt="unpack(myarr)",
238239
number=10,
239240
globals=globals(),
240241
)
241-
python_array_dt_exe_time = timeit.timeit(
242-
setup="myarr2=pack([datetime.now() for x in range (1900, 2000)])",
242+
baseline_exe_time = timeit.timeit(
243+
setup="myarr2=pack(np.array([datetime(2022,10,13,3,3,13) for _ in range (0, 10000)]))",
243244
stmt="unpack(myarr2)",
244245
number=10,
245246
globals=globals(),
246247
)
247248

248-
assert np_array_dt_exe_time < python_array_dt_exe_time
249+
assert optimized_exe_time * 1000 < baseline_exe_time

0 commit comments

Comments
 (0)