Skip to content

Commit

Permalink
fix: fix list failing without order_by and local sorting (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha-gitg committed Apr 14, 2021
1 parent 272fc68 commit 06e99db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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

0 comments on commit 06e99db

Please sign in to comment.