-
Notifications
You must be signed in to change notification settings - Fork 94
Closed
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviortriageIndicates issues, pull requests, or discussions need to be reviewed for the first timeIndicates issues, pull requests, or discussions need to be reviewed for the first time
Description
Bug Report
Description
Now that fetch has returned for backwards compatibility. I see 3 differences which might still lead to issues:
- fetch seems not to be classmethod anymore
- fetch defaults to as_dict=True in dj.2.0 but was as_dict=False in dj.0.14
- fetch('KEY') doesnt work
Reproducibility
import numpy as np
import datajoint as dj
dj.conn() # using datajoint.json
schema = dj.Schema("TEST")
@schema
class RandomLookup(dj.Lookup):
definition = """
idx: int32
---
values1: float32
"""
contents = [(0, 0.0), (1, 1.0), (2, 2.0), (3, 3.0), (4, 4.0)]
RandomLookup.fetch('values1') # works in dj.014
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[38], line 1
----> 1 RandomLookup.fetch('values1')
File ~/datajoint-python/src/datajoint/expression.py:654, in QueryExpression.fetch(self, offset, limit, order_by, format, as_dict, squeeze, *attrs)
651 return self.to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
653 # Default: return structured array (legacy behavior)
--> 654 return self.to_arrays(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
AttributeError: 'str' object has no attribute 'to_arrays'
print(isinstance(RandomLookup().fetch('values1')[0],dict)) # True
print(isinstance(RandomLookup().fetch('values1',as_dict=False)[0],dict)) # False
RandomNumbers().fetch('KEY')
---------------------------------------------------------------------------
DataJointError Traceback (most recent call last)
Cell In[41], line 1
----> 1 RandomNumbers().fetch('KEY')
File ~/datajoint-python/src/datajoint/expression.py:644, in QueryExpression.fetch(self, offset, limit, order_by, format, as_dict, squeeze, *attrs)
641 if attrs:
642 if as_dict or as_dict is None:
643 # fetch('col1', 'col2', as_dict=True) or fetch('col1', 'col2')
--> 644 return self.proj(*attrs).to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
645 else:
646 # fetch('col1', 'col2', as_dict=False) -> tuple of arrays
647 return self.to_arrays(*attrs, order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
File ~/datajoint-python/src/datajoint/expression.py:498, in QueryExpression.proj(self, *attributes, **named_attributes)
496 # check that all attributes exist in heading
497 try:
--> 498 raise DataJointError("Attribute `%s` not found." % next(a for a in attributes if a not in self.heading.names))
499 except StopIteration:
500 pass # all ok
DataJointError: Attribute `KEY` not found.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviortriageIndicates issues, pull requests, or discussions need to be reviewed for the first timeIndicates issues, pull requests, or discussions need to be reviewed for the first time