Skip to content

Commit

Permalink
Allow creating empty slices (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-lucas authored Feb 29, 2024
1 parent 2d7b350 commit db9d5f2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions nucleus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
KEYPOINTS_TYPE = "keypoints"
CATEGORY_TYPE = "category"
MULTICATEGORY_TYPE = "multicategory"
ALLOW_EMPTY = "allow_empty"
ANNOTATION_TYPES = (
BOX_TYPE,
LINE_TYPE,
Expand Down
13 changes: 9 additions & 4 deletions nucleus/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -937,23 +938,27 @@ 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.
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"
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nucleusapi@scaleapi.com>"]
Expand Down

0 comments on commit db9d5f2

Please sign in to comment.