From db9d5f2e1b3b7a9fc4d91b1a596025b50e0b5b27 Mon Sep 17 00:00:00 2001 From: Jean Lucas Date: Thu, 29 Feb 2024 11:13:28 +0100 Subject: [PATCH] Allow creating empty slices (#434) --- CHANGELOG.md | 12 ++++++++++++ nucleus/constants.py | 1 + nucleus/dataset.py | 13 +++++++++---- pyproject.toml | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4228591..aab52d3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.17.2](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.17.2) - 2024-02-28 + +### Modified +- In `Dataset.create_slice`, the `reference_ids` parameter is now optional. If left unspecified, it will create an empty slice + + +## [0.17.1](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.17.1) - 2024-02-22 + +### Added +- Environment variable `NUCLEUS_SKIP_SSL_VERIFY` to skip SSL verification on requests + + ## [0.17.0](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.17.0) - 2024-02-06 ### Added diff --git a/nucleus/constants.py b/nucleus/constants.py index ba23ea59..8a0e83ca 100644 --- a/nucleus/constants.py +++ b/nucleus/constants.py @@ -13,6 +13,7 @@ KEYPOINTS_TYPE = "keypoints" CATEGORY_TYPE = "category" MULTICATEGORY_TYPE = "multicategory" +ALLOW_EMPTY = "allow_empty" ANNOTATION_TYPES = ( BOX_TYPE, LINE_TYPE, diff --git a/nucleus/dataset.py b/nucleus/dataset.py index aca0d826..7be89532 100644 --- a/nucleus/dataset.py +++ b/nucleus/dataset.py @@ -36,6 +36,7 @@ from .annotation import Annotation, check_all_mask_paths_remote from .constants import ( + ALLOW_EMPTY, ANNOTATIONS_KEY, AUTOTAG_SCORE_THRESHOLD, BACKFILL_JOB_KEY, @@ -937,15 +938,14 @@ def ground_truth_loc(self, reference_id: str, annotation_id: str): return Annotation.from_json(response) def create_slice( - self, - name: str, - reference_ids: List[str], + self, name: str, reference_ids: Optional[List[str]] = None ) -> Slice: """Creates a :class:`Slice` of dataset items within a dataset. Parameters: name: A human-readable name for the slice. reference_ids: List of reference IDs of dataset items to add to the slice, cannot exceed 10,000 items. + Can be left unspecified, and an empty slice will be created. Returns: :class:`Slice`: The newly constructed slice item. @@ -953,7 +953,12 @@ def create_slice( Raises: BadRequest: If length of reference_ids is too large (> 10,000 items) """ - payload = {NAME_KEY: name, REFERENCE_IDS_KEY: reference_ids} + payload = {NAME_KEY: name} # type: Dict[str, Any] + if reference_ids: + payload[REFERENCE_IDS_KEY] = reference_ids + else: + payload[ALLOW_EMPTY] = 1 + response = self._client.make_request( payload, f"dataset/{self.id}/create_slice" ) diff --git a/pyproject.toml b/pyproject.toml index d4a2bf78..ce7d6797 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ ignore = ["E501", "E741", "E731", "F401"] # Easy ignore for getting it running [tool.poetry] name = "scale-nucleus" -version = "0.17.1" +version = "0.17.2" description = "The official Python client library for Nucleus, the Data Platform for AI" license = "MIT" authors = ["Scale AI Nucleus Team "]