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: fix list failing without order_by and local sorting #320

Merged
merged 1 commit into from Apr 14, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions google/cloud/aiplatform/base.py
Expand Up @@ -923,14 +923,15 @@ def _list_with_local_order(
credentials=credentials,
)

desc = "desc" in order_by
order_by = order_by.replace("desc", "")
order_by = order_by.split(",")
if order_by:
desc = "desc" in order_by
order_by = order_by.replace("desc", "")
order_by = order_by.split(",")

li.sort(
key=lambda x: tuple(getattr(x, field.strip()) for field in order_by),
reverse=desc,
)
li.sort(
key=lambda x: tuple(getattr(x, field.strip()) for field in order_by),
reverse=desc,
)

return li

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/aiplatform/test_datasets.py
Expand Up @@ -849,6 +849,20 @@ def test_list_dataset(self, list_datasets_mock):
for ds in ds_list:
assert type(ds) == aiplatform.TabularDataset

def test_list_dataset_no_order_or_filter(self, list_datasets_mock):

ds_list = aiplatform.TabularDataset.list()

list_datasets_mock.assert_called_once_with(
request={"parent": _TEST_PARENT, "filter": None}
)

# Ensure returned list is smaller since it filtered out non-tabular datasets
assert len(ds_list) < len(_TEST_DATASET_LIST)

for ds in ds_list:
assert type(ds) == aiplatform.TabularDataset


class TestTextDataset:
def setup_method(self):
Expand Down