From e0d6f9894ae1fe98a6b68e43723ba62c41b1c2e0 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:00:00 -0500 Subject: [PATCH 01/11] Removed data row ids in lists --- libs/labelbox/src/labelbox/schema/project.py | 154 ++---------------- .../test_export_project_streamable.py | 5 +- .../test_labeling_parameter_overrides.py | 107 ------------ .../tests/integration/test_task_queue.py | 4 +- 4 files changed, 19 insertions(+), 251 deletions(-) delete mode 100644 libs/labelbox/tests/integration/test_labeling_parameter_overrides.py diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 3e2cca9d6..fba4c771b 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -67,9 +67,7 @@ DataRowPriority = int -LabelingParameterOverrideInput = Tuple[ - Union[DataRow, DataRowIdentifier], DataRowPriority -] +LabelingParameterOverrideInput = Tuple[DataRowIdentifier, DataRowPriority] logger = logging.getLogger(__name__) MAX_SYNC_BATCH_ROW_COUNT = 1_000 @@ -81,21 +79,13 @@ def validate_labeling_parameter_overrides( for idx, row in enumerate(data): if len(row) < 2: raise TypeError( - f"Data must be a list of tuples each containing two elements: a DataRow or a DataRowIdentifier and priority (int). Found {len(row)} items. Index: {idx}" + f"Data must be a list of tuples each containing two elements: a DataRowIdentifier and priority (int). Found {len(row)} items. Index: {idx}" ) data_row_identifier = row[0] priority = row[1] - valid_types = (Entity.DataRow, UniqueId, GlobalKey) - if not isinstance(data_row_identifier, valid_types): - raise TypeError( - f"Data row identifier should be be of type DataRow, UniqueId or GlobalKey. Found {type(data_row_identifier)} for data_row_identifier {data_row_identifier}" - ) if not isinstance(priority, int): - if isinstance(data_row_identifier, Entity.DataRow): - id = data_row_identifier.uid - else: - id = data_row_identifier + id = data_row_identifier raise TypeError( f"Priority must be an int. Found {type(priority)} for data_row_identifier {id}" ) @@ -1046,57 +1036,6 @@ def _create_batch_async( return self.client.get_batch(self.uid, batch_id) - def _update_queue_mode(self, mode: "QueueMode") -> "QueueMode": - """ - Updates the queueing mode of this project. - - Deprecation notice: This method is deprecated. Going forward, projects must - go through a migration to have the queue mode changed. Users should specify the - queue mode for a project during creation if a non-default mode is desired. - - For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes - - Args: - mode: the specified queue mode - - Returns: the updated queueing mode of this project - - """ - - logger.warning( - "Updating the queue_mode for a project will soon no longer be supported." - ) - - if self.queue_mode == mode: - return mode - - if mode == QueueMode.Batch: - status = "ENABLED" - elif mode == QueueMode.Dataset: - status = "DISABLED" - else: - raise ValueError( - "Must provide either `BATCH` or `DATASET` as a mode" - ) - - query_str = ( - """mutation %s($projectId: ID!, $status: TagSetStatusInput!) { - project(where: {id: $projectId}) { - setTagSetStatus(input: {tagSetStatus: $status}) { - tagSetStatus - } - } - } - """ - % "setTagSetStatusPyApi" - ) - - self.client.execute( - query_str, {"projectId": self.uid, "status": status} - ) - - return mode - def get_label_count(self) -> int: """ Returns: the total number of labels in this project. @@ -1111,46 +1050,6 @@ def get_label_count(self) -> int: res = self.client.execute(query_str, {"projectId": self.uid}) return res["project"]["labelCount"] - def get_queue_mode(self) -> "QueueMode": - """ - Provides the queue mode used for this project. - - Deprecation notice: This method is deprecated and will be removed in - a future version. To obtain the queue mode of a project, simply refer - to the queue_mode attribute of a Project. - - For more information, visit https://docs.labelbox.com/reference/migrating-to-workflows#upcoming-changes - - Returns: the QueueMode for this project - - """ - - logger.warning( - "Obtaining the queue_mode for a project through this method will soon" - " no longer be supported." - ) - - query_str = ( - """query %s($projectId: ID!) { - project(where: {id: $projectId}) { - tagSetStatus - } - } - """ - % "GetTagSetStatusPyApi" - ) - - status = self.client.execute(query_str, {"projectId": self.uid})[ - "project" - ]["tagSetStatus"] - - if status == "ENABLED": - return QueueMode.Batch - elif status == "DISABLED": - return QueueMode.Dataset - else: - raise ValueError("Status not known") - def add_model_config(self, model_config_id: str) -> str: """Adds a model config to this project. @@ -1251,10 +1150,8 @@ def set_labeling_parameter_overrides( Args: data (iterable): An iterable of tuples. Each tuple must contain - either (DataRow, DataRowPriority) - or (DataRowIdentifier, priority) for the new override. + (DataRowIdentifier, priority) for the new override. DataRowIdentifier is an object representing a data row id or a global key. A DataIdentifier object can be a UniqueIds or GlobalKeys class. - NOTE - passing whole DatRow is deprecated. Please use a DataRowIdentifier instead. Priority: * Data will be labeled in priority order. @@ -1283,15 +1180,13 @@ def set_labeling_parameter_overrides( data_rows_with_identifiers = "" for data_row, priority in data: - if isinstance(data_row, DataRow): - data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.uid}", idType: {IdType.DataRowId}}}, priority: {priority}}},' - elif isinstance(data_row, UniqueId) or isinstance( + if isinstance(data_row, UniqueId) or isinstance( data_row, GlobalKey ): data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},' else: raise TypeError( - f"Data row identifier should be be of type DataRow or Data Row Identifier. Found {type(data_row)}." + f"Data row identifier should be be of type Data Row Identifier. Found {type(data_row)}." ) query_str = template.substitute( @@ -1300,26 +1195,10 @@ def set_labeling_parameter_overrides( res = self.client.execute(query_str, {"projectId": self.uid}) return res["project"]["setLabelingParameterOverrides"]["success"] - @overload def update_data_row_labeling_priority( self, data_rows: DataRowIdentifiers, priority: int, - ) -> bool: - pass - - @overload - def update_data_row_labeling_priority( - self, - data_rows: List[str], - priority: int, - ) -> bool: - pass - - def update_data_row_labeling_priority( - self, - data_rows, - priority: int, ) -> bool: """ Updates labeling parameter overrides to this project in bulk. This method allows up to 1 million data rows to be @@ -1329,7 +1208,7 @@ def update_data_row_labeling_priority( https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system Args: - data_rows: a list of data row ids to update priorities for. This can be a list of strings or a DataRowIdentifiers object + data_rows: a list of data row identifiers to update priorities. DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class. priority (int): Priority for the new override. See above for more information. @@ -1337,8 +1216,8 @@ def update_data_row_labeling_priority( bool, indicates if the operation was a success. """ - if isinstance(data_rows, list): - data_rows = UniqueIds(data_rows) + if not isinstance(data_rows[0], DataRowIdentifiers): + raise TypeError("data_rows must be a list of DataRowIdentifiers") method = "createQueuePriorityUpdateTask" priority_param = "priority" @@ -1481,19 +1360,9 @@ def task_queues(self) -> List[TaskQueue]: for field_values in task_queue_values ] - @overload def move_data_rows_to_task_queue( self, data_row_ids: DataRowIdentifiers, task_queue_id: str ): - pass - - @overload - def move_data_rows_to_task_queue( - self, data_row_ids: List[str], task_queue_id: str - ): - pass - - def move_data_rows_to_task_queue(self, data_row_ids, task_queue_id: str): """ Moves data rows to the specified task queue. @@ -1507,8 +1376,9 @@ def move_data_rows_to_task_queue(self, data_row_ids, task_queue_id: str): None if successful, or a raised error on failure """ - if isinstance(data_row_ids, list): - data_row_ids = UniqueIds(data_row_ids) + + if not isinstance(data_row_ids[0], DataRowIdentifiers): + raise TypeError("data_rows must be a list of DataRowIdentifiers") method = "createBulkAddRowsToQueueTask" query_str = ( diff --git a/libs/labelbox/tests/data/export/streamable/test_export_project_streamable.py b/libs/labelbox/tests/data/export/streamable/test_export_project_streamable.py index 63423202a..597c529aa 100644 --- a/libs/labelbox/tests/data/export/streamable/test_export_project_streamable.py +++ b/libs/labelbox/tests/data/export/streamable/test_export_project_streamable.py @@ -9,6 +9,7 @@ from labelbox import Project, Dataset from labelbox.schema.data_row import DataRow from labelbox.schema.label import Label +from labelbox import UniqueIds IMAGE_URL = "https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/potato.jpeg" @@ -128,7 +129,9 @@ def test_with_date_filters( review_queue = next( tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE" ) - project.move_data_rows_to_task_queue([data_row.uid], review_queue.uid) + project.move_data_rows_to_task_queue( + UniqueIds([data_row.uid]), review_queue.uid + ) export_task = project_export( project, task_name, filters=filters, params=params ) diff --git a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py deleted file mode 100644 index bd14040de..000000000 --- a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py +++ /dev/null @@ -1,107 +0,0 @@ -import pytest -from labelbox import DataRow -from labelbox.schema.identifiable import GlobalKey, UniqueId -from labelbox.schema.identifiables import GlobalKeys, UniqueIds - - -def test_labeling_parameter_overrides(consensus_project_with_batch): - [project, _, data_rows] = consensus_project_with_batch - - init_labeling_parameter_overrides = list( - project.labeling_parameter_overrides() - ) - assert len(init_labeling_parameter_overrides) == 3 - assert {o.number_of_labels for o in init_labeling_parameter_overrides} == { - 1, - 1, - 1, - } - assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5} - assert {o.data_row().uid for o in init_labeling_parameter_overrides} == { - data_rows[0].uid, - data_rows[1].uid, - data_rows[2].uid, - } - - data = [(data_rows[0], 4, 2), (data_rows[1], 3)] - success = project.set_labeling_parameter_overrides(data) - assert success - - updated_overrides = list(project.labeling_parameter_overrides()) - assert len(updated_overrides) == 3 - assert {o.number_of_labels for o in updated_overrides} == {1, 1, 1} - assert {o.priority for o in updated_overrides} == {4, 3, 5} - - for override in updated_overrides: - assert isinstance(override.data_row(), DataRow) - - data = [ - (UniqueId(data_rows[0].uid), 1, 2), - (UniqueId(data_rows[1].uid), 2), - (UniqueId(data_rows[2].uid), 3), - ] - success = project.set_labeling_parameter_overrides(data) - assert success - updated_overrides = list(project.labeling_parameter_overrides()) - assert len(updated_overrides) == 3 - assert {o.number_of_labels for o in updated_overrides} == {1, 1, 1} - assert {o.priority for o in updated_overrides} == {1, 2, 3} - - data = [ - (GlobalKey(data_rows[0].global_key), 2, 2), - (GlobalKey(data_rows[1].global_key), 3, 3), - (GlobalKey(data_rows[2].global_key), 4), - ] - success = project.set_labeling_parameter_overrides(data) - assert success - updated_overrides = list(project.labeling_parameter_overrides()) - assert len(updated_overrides) == 3 - assert {o.number_of_labels for o in updated_overrides} == {1, 1, 1} - assert {o.priority for o in updated_overrides} == {2, 3, 4} - - with pytest.raises(TypeError) as exc_info: - data = [(data_rows[2], "a_string", 3)] - project.set_labeling_parameter_overrides(data) - assert ( - str(exc_info.value) - == f"Priority must be an int. Found for data_row_identifier {data_rows[2].uid}" - ) - - with pytest.raises(TypeError) as exc_info: - data = [(data_rows[2].uid, 1)] - project.set_labeling_parameter_overrides(data) - assert ( - str(exc_info.value) - == f"Data row identifier should be be of type DataRow, UniqueId or GlobalKey. Found for data_row_identifier {data_rows[2].uid}" - ) - - -def test_set_labeling_priority(consensus_project_with_batch): - [project, _, data_rows] = consensus_project_with_batch - - init_labeling_parameter_overrides = list( - project.labeling_parameter_overrides() - ) - assert len(init_labeling_parameter_overrides) == 3 - assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5} - - data = [data_row.uid for data_row in data_rows] - success = project.update_data_row_labeling_priority(data, 1) - lo = list(project.labeling_parameter_overrides()) - assert success - assert len(lo) == 3 - assert {o.priority for o in lo} == {1, 1, 1} - - data = [data_row.uid for data_row in data_rows] - success = project.update_data_row_labeling_priority(UniqueIds(data), 2) - lo = list(project.labeling_parameter_overrides()) - assert success - assert len(lo) == 3 - assert {o.priority for o in lo} == {2, 2, 2} - - data = [data_row.global_key for data_row in data_rows] - success = project.update_data_row_labeling_priority(GlobalKeys(data), 3) - lo = list(project.labeling_parameter_overrides()) - assert success - assert len(lo) == 3 - assert {o.priority for o in lo} == {3, 3, 3} diff --git a/libs/labelbox/tests/integration/test_task_queue.py b/libs/labelbox/tests/integration/test_task_queue.py index 835f67219..0cd66cb62 100644 --- a/libs/labelbox/tests/integration/test_task_queue.py +++ b/libs/labelbox/tests/integration/test_task_queue.py @@ -68,7 +68,9 @@ def test_move_to_task(configured_batch_project_with_label): review_queue = next( tq for tq in task_queues if tq.queue_type == "MANUAL_REVIEW_QUEUE" ) - project.move_data_rows_to_task_queue([data_row.uid], review_queue.uid) + project.move_data_rows_to_task_queue( + UniqueIds([data_row.uid]), review_queue.uid + ) _validate_moved(project, "MANUAL_REVIEW_QUEUE", 1) review_queue = next( From a3e1100963a31aaf8f273eecc76d977230f17d68 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:14:44 -0500 Subject: [PATCH 02/11] added back test --- .../test_labeling_parameter_overrides.py | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 libs/labelbox/tests/integration/test_labeling_parameter_overrides.py diff --git a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py new file mode 100644 index 000000000..76355c39b --- /dev/null +++ b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py @@ -0,0 +1,107 @@ +import pytest +from labelbox import DataRow +from labelbox.schema.identifiable import GlobalKey, UniqueId +from labelbox.schema.identifiables import GlobalKeys, UniqueIds + + +def test_labeling_parameter_overrides(consensus_project_with_batch): + [project, _, data_rows] = consensus_project_with_batch + + init_labeling_parameter_overrides = list( + project.labeling_parameter_overrides() + ) + assert len(init_labeling_parameter_overrides) == 3 + assert {o.number_of_labels for o in init_labeling_parameter_overrides} == { + 1, + 1, + 1, + } + assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5} + assert {o.data_row().uid for o in init_labeling_parameter_overrides} == { + data_rows[0].uid, + data_rows[1].uid, + data_rows[2].uid, + } + + data = [(UniqueId(data_rows[0]), 4, 2), (UniqueId(data_rows[1]), 3)] + success = project.set_labeling_parameter_overrides(data) + assert success + + updated_overrides = list(project.labeling_parameter_overrides()) + assert len(updated_overrides) == 3 + assert {o.number_of_labels for o in updated_overrides} == {1, 1, 1} + assert {o.priority for o in updated_overrides} == {4, 3, 5} + + for override in updated_overrides: + assert isinstance(override.data_row(), DataRow) + + data = [ + (UniqueId(data_rows[0].uid), 1, 2), + (UniqueId(data_rows[1].uid), 2), + (UniqueId(data_rows[2].uid), 3), + ] + success = project.set_labeling_parameter_overrides(data) + assert success + updated_overrides = list(project.labeling_parameter_overrides()) + assert len(updated_overrides) == 3 + assert {o.number_of_labels for o in updated_overrides} == {1, 1, 1} + assert {o.priority for o in updated_overrides} == {1, 2, 3} + + data = [ + (GlobalKey(data_rows[0].global_key), 2, 2), + (GlobalKey(data_rows[1].global_key), 3, 3), + (GlobalKey(data_rows[2].global_key), 4), + ] + success = project.set_labeling_parameter_overrides(data) + assert success + updated_overrides = list(project.labeling_parameter_overrides()) + assert len(updated_overrides) == 3 + assert {o.number_of_labels for o in updated_overrides} == {1, 1, 1} + assert {o.priority for o in updated_overrides} == {2, 3, 4} + + with pytest.raises(TypeError) as exc_info: + data = [(data_rows[2], "a_string", 3)] + project.set_labeling_parameter_overrides(data) + assert ( + str(exc_info.value) + == f"Priority must be an int. Found for data_row_identifier {data_rows[2].uid}" + ) + + with pytest.raises(TypeError) as exc_info: + data = [(data_rows[2].uid, 1)] + project.set_labeling_parameter_overrides(data) + assert ( + str(exc_info.value) + == f"Data row identifier should be be of type DataRow, UniqueId or GlobalKey. Found for data_row_identifier {data_rows[2].uid}" + ) + + +def test_set_labeling_priority(consensus_project_with_batch): + [project, _, data_rows] = consensus_project_with_batch + + init_labeling_parameter_overrides = list( + project.labeling_parameter_overrides() + ) + assert len(init_labeling_parameter_overrides) == 3 + assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5} + + data = [data_row.uid for data_row in data_rows] + success = project.update_data_row_labeling_priority(data, 1) + lo = list(project.labeling_parameter_overrides()) + assert success + assert len(lo) == 3 + assert {o.priority for o in lo} == {1, 1, 1} + + data = [data_row.uid for data_row in data_rows] + success = project.update_data_row_labeling_priority(UniqueIds(data), 2) + lo = list(project.labeling_parameter_overrides()) + assert success + assert len(lo) == 3 + assert {o.priority for o in lo} == {2, 2, 2} + + data = [data_row.global_key for data_row in data_rows] + success = project.update_data_row_labeling_priority(GlobalKeys(data), 3) + lo = list(project.labeling_parameter_overrides()) + assert success + assert len(lo) == 3 + assert {o.priority for o in lo} == {3, 3, 3} From e5c3212045176d84ec92e71ac14e9dfbfc193990 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:20:21 -0500 Subject: [PATCH 03/11] Fixed execute error --- libs/labelbox/src/labelbox/schema/project.py | 5 +---- .../tests/integration/test_labeling_parameter_overrides.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index fba4c771b..7d4f2a3b0 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -1142,9 +1142,6 @@ def set_labeling_parameter_overrides( See information on priority here: https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system - >>> project.set_labeling_parameter_overrides([ - >>> (data_row_id1, 2), (data_row_id2, 1)]) - or >>> project.set_labeling_parameter_overrides([ >>> (data_row_gk1, 2), (data_row_gk2, 1)]) @@ -1186,7 +1183,7 @@ def set_labeling_parameter_overrides( data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},' else: raise TypeError( - f"Data row identifier should be be of type Data Row Identifier. Found {type(data_row)}." + f"Data row identifier should be of type Data Row Identifier. Found {type(data_row)}." ) query_str = template.substitute( diff --git a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py index 76355c39b..f037f7a57 100644 --- a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py +++ b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py @@ -72,7 +72,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch): project.set_labeling_parameter_overrides(data) assert ( str(exc_info.value) - == f"Data row identifier should be be of type DataRow, UniqueId or GlobalKey. Found for data_row_identifier {data_rows[2].uid}" + == f"Data row identifier should be of type Data Row Identifier. Found " ) From 62bb313f5889acfd31a607bc4cafe7fecee3561d Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:57:30 -0500 Subject: [PATCH 04/11] Fixed error --- ...project_validate_labeling_parameter_overrides.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libs/labelbox/tests/unit/test_unit_project_validate_labeling_parameter_overrides.py b/libs/labelbox/tests/unit/test_unit_project_validate_labeling_parameter_overrides.py index 7f6d29d5a..8e6c38559 100644 --- a/libs/labelbox/tests/unit/test_unit_project_validate_labeling_parameter_overrides.py +++ b/libs/labelbox/tests/unit/test_unit_project_validate_labeling_parameter_overrides.py @@ -6,19 +6,6 @@ from labelbox.schema.project import validate_labeling_parameter_overrides -def test_validate_labeling_parameter_overrides_valid_data(): - mock_data_row = MagicMock(spec=DataRow) - mock_data_row.uid = "abc" - data = [(mock_data_row, 1), (UniqueId("efg"), 2), (GlobalKey("hij"), 3)] - validate_labeling_parameter_overrides(data) - - -def test_validate_labeling_parameter_overrides_invalid_data(): - data = [("abc", 1), (UniqueId("efg"), 2), (GlobalKey("hij"), 3)] - with pytest.raises(TypeError): - validate_labeling_parameter_overrides(data) - - def test_validate_labeling_parameter_overrides_invalid_priority(): mock_data_row = MagicMock(spec=DataRow) mock_data_row.uid = "abc" From c63fd142fdb0109b05727d3659460b13ea57da30 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 08:43:45 -0500 Subject: [PATCH 05/11] Fix tests --- libs/labelbox/src/labelbox/schema/project.py | 6 +++--- .../tests/integration/test_labeling_parameter_overrides.py | 7 ------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 7d4f2a3b0..4e960e91e 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -1365,7 +1365,7 @@ def move_data_rows_to_task_queue( Moves data rows to the specified task queue. Args: - data_row_ids: a list of data row ids to be moved. This can be a list of strings or a DataRowIdentifiers object + data_row_ids: a list of data row ids to be moved. This should be a DataRowIdentifiers object DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class. task_queue_id: the task queue id to be moved to, or None to specify the "Done" queue @@ -1374,8 +1374,8 @@ def move_data_rows_to_task_queue( """ - if not isinstance(data_row_ids[0], DataRowIdentifiers): - raise TypeError("data_rows must be a list of DataRowIdentifiers") + if not isinstance(data_row_ids, DataRowIdentifiers): + raise TypeError("data_rows must a DataRowIdentifiers object") method = "createBulkAddRowsToQueueTask" query_str = ( diff --git a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py index f037f7a57..a0b1819bd 100644 --- a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py +++ b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py @@ -85,13 +85,6 @@ def test_set_labeling_priority(consensus_project_with_batch): assert len(init_labeling_parameter_overrides) == 3 assert {o.priority for o in init_labeling_parameter_overrides} == {5, 5, 5} - data = [data_row.uid for data_row in data_rows] - success = project.update_data_row_labeling_priority(data, 1) - lo = list(project.labeling_parameter_overrides()) - assert success - assert len(lo) == 3 - assert {o.priority for o in lo} == {1, 1, 1} - data = [data_row.uid for data_row in data_rows] success = project.update_data_row_labeling_priority(UniqueIds(data), 2) lo = list(project.labeling_parameter_overrides()) From 172e3f178930902e3abe2ff2870ba99b17c7bcb0 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 09:07:06 -0500 Subject: [PATCH 06/11] Fixed type checker --- libs/labelbox/src/labelbox/schema/project.py | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 4e960e91e..692761844 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -13,7 +13,6 @@ Optional, Tuple, Union, - overload, ) from lbox.exceptions import ( @@ -40,7 +39,11 @@ from labelbox.schema.export_task import ExportTask from labelbox.schema.id_type import IdType from labelbox.schema.identifiable import DataRowIdentifier, GlobalKey, UniqueId -from labelbox.schema.identifiables import DataRowIdentifiers, UniqueIds +from labelbox.schema.identifiables import ( + DataRowIdentifiers, + GlobalKeys, + UniqueIds, +) from labelbox.schema.labeling_service import ( LabelingService, LabelingServiceStatus, @@ -1205,7 +1208,7 @@ def update_data_row_labeling_priority( https://docs.labelbox.com/en/configure-editor/queue-system#reservation-system Args: - data_rows: a list of data row identifiers to update priorities. + data_rows: data row identifiers object to update priorities. DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class. priority (int): Priority for the new override. See above for more information. @@ -1213,8 +1216,10 @@ def update_data_row_labeling_priority( bool, indicates if the operation was a success. """ - if not isinstance(data_rows[0], DataRowIdentifiers): - raise TypeError("data_rows must be a list of DataRowIdentifiers") + if not isinstance(data_rows, UniqueIds) or not isinstance( + data_rows, GlobalKeys + ): + raise TypeError("data_rows must be a DataRowIdentifiers object") method = "createQueuePriorityUpdateTask" priority_param = "priority" @@ -1374,8 +1379,10 @@ def move_data_rows_to_task_queue( """ - if not isinstance(data_row_ids, DataRowIdentifiers): - raise TypeError("data_rows must a DataRowIdentifiers object") + if not isinstance(data_row_ids, UniqueIds) or not isinstance( + data_row_ids, GlobalKeys + ): + raise TypeError("data_rows must be a DataRowIdentifiers object") method = "createBulkAddRowsToQueueTask" query_str = ( From ccb4d920fd1086c9efcf49539ae18545d7dab900 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 09:26:36 -0500 Subject: [PATCH 07/11] Fix test --- libs/labelbox/src/labelbox/schema/project.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 692761844..4b56430c9 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -13,6 +13,7 @@ Optional, Tuple, Union, + get_args, ) from lbox.exceptions import ( @@ -1216,8 +1217,8 @@ def update_data_row_labeling_priority( bool, indicates if the operation was a success. """ - if not isinstance(data_rows, UniqueIds) or not isinstance( - data_rows, GlobalKeys + if not isinstance(data_rows, get_args(UniqueIds)) or not isinstance( + data_rows, get_args(GlobalKeys) ): raise TypeError("data_rows must be a DataRowIdentifiers object") @@ -1379,8 +1380,8 @@ def move_data_rows_to_task_queue( """ - if not isinstance(data_row_ids, UniqueIds) or not isinstance( - data_row_ids, GlobalKeys + if not isinstance(data_row_ids, get_args(UniqueIds)) or not isinstance( + data_row_ids, get_args(GlobalKeys) ): raise TypeError("data_rows must be a DataRowIdentifiers object") From e5321dde862a10182c640ded1691eb2bdf12cd67 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 09:31:25 -0500 Subject: [PATCH 08/11] Last fix --- libs/labelbox/src/labelbox/schema/project.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 4b56430c9..65b898d4d 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -1217,9 +1217,7 @@ def update_data_row_labeling_priority( bool, indicates if the operation was a success. """ - if not isinstance(data_rows, get_args(UniqueIds)) or not isinstance( - data_rows, get_args(GlobalKeys) - ): + if not isinstance(data_rows, get_args(DataRowIdentifiers)): raise TypeError("data_rows must be a DataRowIdentifiers object") method = "createQueuePriorityUpdateTask" @@ -1380,9 +1378,7 @@ def move_data_rows_to_task_queue( """ - if not isinstance(data_row_ids, get_args(UniqueIds)) or not isinstance( - data_row_ids, get_args(GlobalKeys) - ): + if not isinstance(data_row_ids, get_args(DataRowIdentifiers)): raise TypeError("data_rows must be a DataRowIdentifiers object") method = "createBulkAddRowsToQueueTask" From a31963ab58f3cb20022edc41de34f5eb0e532e28 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:38:21 -0500 Subject: [PATCH 09/11] simplified conditional --- libs/labelbox/src/labelbox/schema/project.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index 65b898d4d..bab44361e 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -1181,9 +1181,7 @@ def set_labeling_parameter_overrides( data_rows_with_identifiers = "" for data_row, priority in data: - if isinstance(data_row, UniqueId) or isinstance( - data_row, GlobalKey - ): + if isinstance(data_row, get_args(DataRowIdentifier)): data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},' else: raise TypeError( From ae8291604c2868d20696fceb6525203aab95ec6b Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:46:36 -0500 Subject: [PATCH 10/11] fix test --- .../tests/integration/test_labeling_parameter_overrides.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py index a0b1819bd..d96bd2af2 100644 --- a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py +++ b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py @@ -23,7 +23,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch): data_rows[2].uid, } - data = [(UniqueId(data_rows[0]), 4, 2), (UniqueId(data_rows[1]), 3)] + data = [(UniqueId(data_rows[0].uid), 4, 2), (UniqueId(data_rows[1].uid), 3)] success = project.set_labeling_parameter_overrides(data) assert success From fa1764b88c0c7224b4d4a129cb505772dc3dfc71 Mon Sep 17 00:00:00 2001 From: Gabefire <33893811+Gabefire@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:58:09 -0500 Subject: [PATCH 11/11] Fix validation --- libs/labelbox/src/labelbox/schema/project.py | 18 ++++++++---------- .../test_labeling_parameter_overrides.py | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/project.py b/libs/labelbox/src/labelbox/schema/project.py index bab44361e..0daf3af10 100644 --- a/libs/labelbox/src/labelbox/schema/project.py +++ b/libs/labelbox/src/labelbox/schema/project.py @@ -81,15 +81,18 @@ def validate_labeling_parameter_overrides( data: List[LabelingParameterOverrideInput], ) -> None: for idx, row in enumerate(data): + data_row_identifier = row[0] + priority = row[1] + if not isinstance(data_row_identifier, get_args(DataRowIdentifier)): + raise TypeError( + f"Data row identifier should be of type DataRowIdentifier. Found {type(data_row_identifier)}." + ) if len(row) < 2: raise TypeError( f"Data must be a list of tuples each containing two elements: a DataRowIdentifier and priority (int). Found {len(row)} items. Index: {idx}" ) - data_row_identifier = row[0] - priority = row[1] - if not isinstance(priority, int): - id = data_row_identifier + id = data_row_identifier.key raise TypeError( f"Priority must be an int. Found {type(priority)} for data_row_identifier {id}" ) @@ -1181,12 +1184,7 @@ def set_labeling_parameter_overrides( data_rows_with_identifiers = "" for data_row, priority in data: - if isinstance(data_row, get_args(DataRowIdentifier)): - data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},' - else: - raise TypeError( - f"Data row identifier should be of type Data Row Identifier. Found {type(data_row)}." - ) + data_rows_with_identifiers += f'{{dataRowIdentifier: {{id: "{data_row.key}", idType: {data_row.id_type}}}, priority: {priority}}},' query_str = template.substitute( dataWithDataRowIdentifiers=data_rows_with_identifiers diff --git a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py index d96bd2af2..afa038482 100644 --- a/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py +++ b/libs/labelbox/tests/integration/test_labeling_parameter_overrides.py @@ -60,7 +60,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch): assert {o.priority for o in updated_overrides} == {2, 3, 4} with pytest.raises(TypeError) as exc_info: - data = [(data_rows[2], "a_string", 3)] + data = [(UniqueId(data_rows[2].uid), "a_string", 3)] project.set_labeling_parameter_overrides(data) assert ( str(exc_info.value) @@ -72,7 +72,7 @@ def test_labeling_parameter_overrides(consensus_project_with_batch): project.set_labeling_parameter_overrides(data) assert ( str(exc_info.value) - == f"Data row identifier should be of type Data Row Identifier. Found " + == "Data row identifier should be of type DataRowIdentifier. Found ." )