Skip to content

Commit 94c2eb8

Browse files
Merge pull request #706 from dimitri-yatsenko/master
Fix #698 and #699
2 parents 236e46e + 04808ce commit 94c2eb8

File tree

11 files changed

+54
-22
lines changed

11 files changed

+54
-22
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Release notes
22

3+
## 0.12.3 -- Nov 22, 2019
4+
* Bugfix #675 (PR #705) networkx 2.4+ is now supported
5+
* Bugfix #698 and #699 (PR #706) display table definition in doc string and help
6+
* Bugfix #701 (PR #702) job reservation works with native python datatype support disabled
7+
38
### 0.12.2 -- Nov 11, 2019
49
* Bugfix - Convoluted error thrown if there is a reference to a non-existent table attribute (#691)
510
* Bugfix - Insert into external does not trim leading slash if defined in `dj.config['stores']['<store>']['location']` (#692)

datajoint/blob.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,8 @@ def pack_blob(self, obj):
152152
return self.pack_array(np.array(obj))
153153
if isinstance(obj, (bool, np.bool, np.bool_)):
154154
return self.pack_array(np.array(obj))
155-
if isinstance(obj, float):
156-
return self.pack_array(np.array(obj, dtype=np.float64))
157-
if isinstance(obj, int):
158-
return self.pack_array(np.array(obj, dtype=np.int64))
155+
if isinstance(obj, (float, int, complex)):
156+
return self.pack_array(np.array(obj))
159157
if isinstance(obj, (datetime.datetime, datetime.date, datetime.time)):
160158
return self.pack_datetime(obj)
161159
if isinstance(obj, Decimal):

datajoint/heading.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ def init_from_database(self, conn, database, table_name, context):
247247
category = next(c for c in SPECIAL_TYPES if TYPE_PATTERN[c].match(attr['type']))
248248
except StopIteration:
249249
if attr['type'].startswith('external'):
250-
raise DataJointError('Legacy datatype `{type}`.'.format(**attr)) from None
250+
url = "https://docs.datajoint.io/python/admin/5-blob-config.html" \
251+
"#migration-between-datajoint-v0-11-and-v0-12"
252+
raise DataJointError('Legacy datatype `{type}`. Migrate your external stores to '
253+
'datajoint 0.12: {url}'.format(url=url, **attr)) from None
251254
raise DataJointError('Unknown attribute type `{type}`'.format(**attr)) from None
252255
if category == 'FILEPATH' and not _support_filepath_types():
253256
raise DataJointError("""

datajoint/schema.py

+4
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ def process_table_class(self, table_class, context, assert_declared=False):
191191
instance.declare(context)
192192
is_declared = is_declared or instance.is_declared
193193

194+
# add table definition to the doc string
195+
if isinstance(table_class.definition, str):
196+
table_class.__doc__ = (table_class.__doc__ or "") + "\nTable definition:\n\n" + table_class.definition
197+
194198
# fill values in Lookup tables from their contents property
195199
if isinstance(instance, Lookup) and hasattr(instance, 'contents') and is_declared:
196200
contents = list(instance.contents)

datajoint/table.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ def heading(self):
4545
"""
4646
if self._heading is None:
4747
self._heading = Heading() # instance-level heading
48-
if not self._heading: # lazy loading of heading
49-
if self.connection is None:
50-
raise DataJointError(
51-
'DataJoint class is missing a database connection. '
52-
'Missing schema decorator on the class? (e.g. @schema)')
53-
else:
54-
self._heading.init_from_database(
55-
self.connection, self.database, self.table_name, self.declaration_context)
48+
if not self._heading and self.connection is not None: # lazy loading of heading
49+
self._heading.init_from_database(
50+
self.connection, self.database, self.table_name, self.declaration_context)
5651
return self._heading
5752

5853
def declare(self, context=None):
@@ -411,7 +406,7 @@ def delete(self, verbose=True):
411406
print('About to delete:')
412407

413408
if not already_in_transaction:
414-
self.connection.start_transaction()
409+
conn.start_transaction()
415410
total = 0
416411
try:
417412
for name, table in reversed(list(delete_list.items())):
@@ -423,25 +418,25 @@ def delete(self, verbose=True):
423418
except:
424419
# Delete failed, perhaps due to insufficient privileges. Cancel transaction.
425420
if not already_in_transaction:
426-
self.connection.cancel_transaction()
421+
conn.cancel_transaction()
427422
raise
428423
else:
429424
assert not (already_in_transaction and safe)
430425
if not total:
431426
print('Nothing to delete')
432427
if not already_in_transaction:
433-
self.connection.cancel_transaction()
428+
conn.cancel_transaction()
434429
else:
435430
if already_in_transaction:
436431
if verbose:
437432
print('The delete is pending within the ongoing transaction.')
438433
else:
439434
if not safe or user_choice("Proceed?", default='no') == 'yes':
440-
self.connection.commit_transaction()
435+
conn.commit_transaction()
441436
if verbose or safe:
442437
print('Committed.')
443438
else:
444-
self.connection.cancel_transaction()
439+
conn.cancel_transaction()
445440
if verbose or safe:
446441
print('Cancelled deletes.')
447442

datajoint/user_tables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# attributes that trigger instantiation of user classes
1414
supported_class_attrs = {
1515
'key_source', 'describe', 'alter', 'heading', 'populate', 'progress', 'primary_key', 'proj', 'aggr',
16-
'fetch', 'fetch1','head', 'tail',
16+
'fetch', 'fetch1', 'head', 'tail',
1717
'insert', 'insert1', 'drop', 'drop_quick', 'delete', 'delete_quick'}
1818

1919

@@ -92,7 +92,7 @@ def table_name(cls):
9292

9393
@ClassProperty
9494
def full_table_name(cls):
95-
if cls not in {Manual, Imported, Lookup, Computed, Part}:
95+
if cls not in {Manual, Imported, Lookup, Computed, Part, UserTable}:
9696
if cls.database is None:
9797
raise DataJointError('Class %s is not properly declared (schema decorator not applied?)' % cls.__name__)
9898
return r"`{0:s}`.`{1:s}`".format(cls.database, cls.table_name)

datajoint/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.12.2"
1+
__version__ = "0.12.3"
22

33
assert len(__version__) <= 10 # The log table limits version to the 10 characters

docs-parts/intro/Releases_lang1.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
0.12.1 -- Nov 11, 2019
1+
0.12.3 -- Nov 22, 2019
2+
----------------------
3+
* Bugfix - networkx 2.4 causes error in diagrams (#675) PR #705
4+
* Bugfix - include definition in doc string and help (#698, #699) PR #706
5+
* Bugfix - job reservation fails when native python datatype support is disabled (#701) PR #702
6+
7+
8+
0.12.2 -- Nov 11, 2019
29
-------------------------
310
* Bugfix - Convoluted error thrown if there is a reference to a non-existent table attribute (#691)
411
* Bugfix - Insert into external does not trim leading slash if defined in `dj.config['stores']['<store>']['location']` (#692)

tests/schema.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
@schema
1515
class TTest(dj.Lookup):
16+
"""
17+
doc string
18+
"""
1619
definition = """
1720
key : int # key
1821
---

tests/test_blob.py

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_pack():
2323
x = np.random.randn(10)
2424
assert_array_equal(x, unpack(pack(x)), "Arrays do not match!")
2525

26+
x = 7j
27+
assert_equal(x, unpack(pack(x)), "Complex scalar does not match")
28+
2629
x = np.float32(np.random.randn(3, 4, 5))
2730
assert_array_equal(x, unpack(pack(x)), "Arrays do not match!")
2831

tests/test_declare.py

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ def test_schema_decorator():
2222
assert_true(issubclass(Subject, dj.Lookup))
2323
assert_true(not issubclass(Subject, dj.Part))
2424

25+
@staticmethod
26+
def test_class_help():
27+
help(TTest)
28+
help(TTest2)
29+
assert_true(TTest.definition in TTest.__doc__)
30+
assert_true(TTest.definition in TTest2.__doc__)
31+
32+
@staticmethod
33+
def test_instance_help():
34+
help(TTest())
35+
help(TTest2())
36+
assert_true(TTest().definition in TTest().__doc__)
37+
assert_true(TTest2().definition in TTest2().__doc__)
38+
2539
@staticmethod
2640
def test_describe():
2741
"""real_definition should match original definition"""

0 commit comments

Comments
 (0)