Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/datajoint/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,12 @@ def fetch(

# Handle specific attributes requested
if attrs:
if as_dict or as_dict is None:
# fetch('col1', 'col2', as_dict=True) or fetch('col1', 'col2')
if as_dict is True:
# fetch('col1', 'col2', as_dict=True) -> list of dicts
return self.proj(*attrs).to_dicts(order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)
else:
# fetch('col1', 'col2', as_dict=False) -> tuple of arrays
# fetch('col1', 'col2') or fetch('col1', 'col2', as_dict=False) -> tuple of arrays
# This matches DJ 1.x behavior where fetch('col') returns array(['alpha', 'beta'])
return self.to_arrays(*attrs, order_by=order_by, limit=limit, offset=offset, squeeze=squeeze)

# Handle as_dict=True -> to_dicts()
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/test_fetch_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,23 @@ def test_fetch_as_dict_true(self, mock_expression):

mock_expression.to_dicts.assert_called_once_with(order_by=None, limit=None, offset=None, squeeze=False)

def test_fetch_with_attrs_returns_dicts(self, mock_expression):
"""fetch('col1', 'col2') should call proj().to_dicts()."""
def test_fetch_with_attrs_returns_arrays(self, mock_expression):
"""fetch('col1', 'col2') should call to_arrays() - matches DJ 1.x behavior."""
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
mock_expression.fetch("col1", "col2")

# DJ 1.x: fetch('col') returns array(['alpha', 'beta']), not list of dicts
mock_expression.to_arrays.assert_called_once_with(
"col1", "col2", order_by=None, limit=None, offset=None, squeeze=False
)

def test_fetch_with_attrs_as_dict_true(self, mock_expression):
"""fetch('col1', 'col2', as_dict=True) should call proj().to_dicts()."""
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
mock_expression.fetch("col1", "col2", as_dict=True)

mock_expression.proj.assert_called_once_with("col1", "col2")
mock_expression.to_dicts.assert_called_once()

Expand Down
Loading