Skip to content

Commit 35e0fd3

Browse files
Update docs and remove deprecated features.
1 parent 713c497 commit 35e0fd3

File tree

6 files changed

+291
-214
lines changed

6 files changed

+291
-214
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
},
1111
"[markdown]": {
1212
"editor.defaultFormatter": "disable"
13-
}
13+
},
14+
"files.autoSave": "off"
1415
}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Release notes
22

3-
### 0.14.0 -- TBA
3+
### 0.14.0 -- Feb 10, 2023
44
- Fixed - Activating a schema requires all tables to exist even if `create_tables=False` PR [#1058](https://github.com/datajoint/datajoint-python/pull/1058)
55
- Changed - Populate call with `reserve_jobs=True` to exclude `error` and `ignore` keys - PR [#1062](https://github.com/datajoint/datajoint-python/pull/1062)
66
- Added - Support for inserting data with CSV files - PR [#1067](https://github.com/datajoint/datajoint-python/pull/1067)

datajoint/condition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def translate_attribute(key):
2525
return match, match["attr"]
2626
else:
2727
return match, "json_value(`{}`, _utf8mb4'$.{}'{})".format(
28-
*{
29-
k: ((f" returning {v}" if k == "type" else v) if v else "")
28+
*[
29+
((f" returning {v}" if k == "type" else v) if v else "")
3030
for k, v in match.items()
31-
}.values()
31+
]
3232
)
3333

3434

datajoint/declare.py

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,14 @@ def compile_foreign_key(
163163
from .table import Table
164164
from .expression import QueryExpression
165165

166-
obsolete = False # See issue #436. Old style to be deprecated in a future release
167166
try:
168167
result = foreign_key_parser.parseString(line)
169-
except pp.ParseException:
170-
try:
171-
result = foreign_key_parser_old.parseString(line)
172-
except pp.ParseBaseException as err:
173-
raise DataJointError('Parsing error in line "%s". %s.' % (line, err))
174-
else:
175-
obsolete = True
168+
except pp.ParseException as err:
169+
raise DataJointError('Parsing error in line "%s". %s.' % (line, err))
170+
176171
try:
177172
ref = eval(result.ref_table, context)
178-
except NameError if obsolete else Exception:
173+
except Exception:
179174
raise DataJointError(
180175
"Foreign key reference %s could not be resolved" % result.ref_table
181176
)
@@ -191,18 +186,6 @@ def compile_foreign_key(
191186
'Primary dependencies cannot be nullable in line "{line}"'.format(line=line)
192187
)
193188

194-
if obsolete:
195-
logger.warning(
196-
'Line "{line}" uses obsolete syntax that will no longer be supported in datajoint 0.14. '
197-
"For details, see issue #780 https://github.com/datajoint/datajoint-python/issues/780".format(
198-
line=line
199-
)
200-
)
201-
if not isinstance(ref, type) or not issubclass(ref, Table):
202-
raise DataJointError(
203-
"Foreign key reference %r must be a valid query" % result.ref_table
204-
)
205-
206189
if isinstance(ref, type) and issubclass(ref, Table):
207190
ref = ref()
208191

@@ -218,55 +201,6 @@ def compile_foreign_key(
218201
% result.ref_table
219202
)
220203

221-
if obsolete:
222-
# for backward compatibility with old-style dependency declarations. See issue #436
223-
if not isinstance(ref, Table):
224-
DataJointError(
225-
'Dependency "%s" is not supported. Check documentation.'
226-
% result.ref_table
227-
)
228-
if not all(r in ref.primary_key for r in result.ref_attrs):
229-
raise DataJointError('Invalid foreign key attributes in "%s"' % line)
230-
try:
231-
raise DataJointError(
232-
'Duplicate attributes "{attr}" in "{line}"'.format(
233-
attr=next(attr for attr in result.new_attrs if attr in attributes),
234-
line=line,
235-
)
236-
)
237-
except StopIteration:
238-
pass # the normal outcome
239-
240-
# Match the primary attributes of the referenced table to local attributes
241-
new_attrs = list(result.new_attrs)
242-
ref_attrs = list(result.ref_attrs)
243-
244-
# special case, the renamed attribute is implicit
245-
if new_attrs and not ref_attrs:
246-
if len(new_attrs) != 1:
247-
raise DataJointError(
248-
'Renamed foreign key must be mapped to the primary key in "%s"'
249-
% line
250-
)
251-
if len(ref.primary_key) == 1:
252-
# if the primary key has one attribute, allow implicit renaming
253-
ref_attrs = ref.primary_key
254-
else:
255-
# if only one primary key attribute remains, then allow implicit renaming
256-
ref_attrs = [attr for attr in ref.primary_key if attr not in attributes]
257-
if len(ref_attrs) != 1:
258-
raise DataJointError(
259-
'Could not resolve which primary key attribute should be referenced in "%s"'
260-
% line
261-
)
262-
263-
if len(new_attrs) != len(ref_attrs):
264-
raise DataJointError('Mismatched attributes in foreign key "%s"' % line)
265-
266-
if ref_attrs:
267-
# convert to projected dependency
268-
ref = ref.proj(**dict(zip(new_attrs, ref_attrs)))
269-
270204
# declare new foreign key attributes
271205
for attr in ref.primary_key:
272206
if attr not in attributes:

datajoint/table.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -774,58 +774,6 @@ def describe(self, context=None, printout=False):
774774
logger.info("\n" + definition)
775775
return definition
776776

777-
def _update(self, attrname, value=None):
778-
"""
779-
This is a deprecated function to be removed in datajoint 0.14.
780-
Use ``.update1`` instead.
781-
782-
Updates a field in one existing tuple. self must be restricted to exactly one entry.
783-
In DataJoint the principal way of updating data is to delete and re-insert the
784-
entire record and updates are reserved for corrective actions.
785-
This is because referential integrity is observed on the level of entire
786-
records rather than individual attributes.
787-
788-
Safety constraints:
789-
1. self must be restricted to exactly one tuple
790-
2. the update attribute must not be in primary key
791-
792-
Example:
793-
>>> (v2p.Mice() & key)._update('mouse_dob', '2011-01-01')
794-
>>> (v2p.Mice() & key)._update( 'lens') # set the value to NULL
795-
"""
796-
logger.warning(
797-
"`_update` is a deprecated function to be removed in datajoint 0.14. "
798-
"Use `.update1` instead."
799-
)
800-
if len(self) != 1:
801-
raise DataJointError("Update is only allowed on one tuple at a time")
802-
if attrname not in self.heading:
803-
raise DataJointError("Invalid attribute name")
804-
if attrname in self.heading.primary_key:
805-
raise DataJointError("Cannot update a key value.")
806-
807-
attr = self.heading[attrname]
808-
809-
if attr.is_blob:
810-
value = blob.pack(value)
811-
placeholder = "%s"
812-
elif attr.numeric:
813-
if value is None or np.isnan(float(value)): # nans are turned into NULLs
814-
placeholder = "NULL"
815-
value = None
816-
else:
817-
placeholder = "%s"
818-
value = str(int(value) if isinstance(value, bool) else value)
819-
else:
820-
placeholder = "%s" if value is not None else "NULL"
821-
command = "UPDATE {full_table_name} SET `{attrname}`={placeholder} {where_clause}".format(
822-
full_table_name=self.from_clause(),
823-
attrname=attrname,
824-
placeholder=placeholder,
825-
where_clause=self.where_clause(),
826-
)
827-
self.connection.query(command, args=(value,) if value is not None else ())
828-
829777
# --- private helper functions ----
830778
def __make_placeholder(self, name, value, ignore_extra_fields=False):
831779
"""

0 commit comments

Comments
 (0)