Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: correct Dataset.descr() implementation #84

Merged
merged 1 commit into from
Apr 17, 2024
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
3 changes: 2 additions & 1 deletion cryosparc/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,8 @@ def descr(self, exclude_uid=False) -> List[Field]:
Returns:
list[Field]: Fields
"""
return [get_data_field(self._data, self._data.key(i)) for i in range(self._data.ncol())]
descr = [get_data_field(self._data, self._data.key(i)) for i in range(self._data.ncol())]
return [f for f in descr if f[0] != "uid"] if exclude_uid else descr

def copy(self):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def test_empty_data_constructor():
assert len(data.descr()) == 1


def test_fields():
data = Dataset.allocate(3, [("test1", "<u4"), ("test2", "<f8", (2,))])
assert data.fields() == ["uid", "test1", "test2"]
assert data.fields(exclude_uid=True) == ["test1", "test2"]


def test_descr():
data = Dataset.allocate(3, [("test1", "<u4"), ("test2", "<f8", (2,))])
expected_descr = [("uid", "<u8"), ("test1", "<u4"), ("test2", "<f8", (2,))]
assert data.descr() == expected_descr
assert data.descr(exclude_uid=True) == expected_descr[1:]


def test_invalid_data_fields():
# This is ok actually
assert Dataset(
Expand Down