|
53 | 53 | ) |
54 | 54 | from .dataset_item_uploader import DatasetItemUploader |
55 | 55 | from .deprecation_warning import deprecated |
56 | | -from .errors import NucleusAPIError |
| 56 | +from .errors import NotFoundError, NucleusAPIError |
57 | 57 | from .metadata_manager import ExportMetadataType, MetadataManager |
58 | 58 | from .payload_constructor import ( |
59 | 59 | construct_append_scenes_payload, |
|
65 | 65 | Slice, |
66 | 66 | SliceBuilderFilters, |
67 | 67 | SliceBuilderMethods, |
| 68 | + SliceType, |
68 | 69 | create_slice_builder_payload, |
69 | 70 | ) |
70 | 71 | from .upload_response import UploadResponse |
@@ -155,12 +156,53 @@ def model_runs(self) -> List[str]: |
155 | 156 | return response |
156 | 157 |
|
157 | 158 | @property |
158 | | - def slices(self) -> List[str]: |
| 159 | + def slices(self) -> List[Slice]: |
159 | 160 | """List of all Slice IDs created from the Dataset.""" |
160 | 161 | response = self._client.make_request( |
161 | 162 | {}, f"dataset/{self.id}/slices", requests.get |
162 | 163 | ) |
163 | | - return response |
| 164 | + return [Slice.from_request(info, self._client) for info in response] |
| 165 | + |
| 166 | + def get_slices( |
| 167 | + self, |
| 168 | + name: Optional[str] = None, |
| 169 | + slice_type: Optional[Union[str, SliceType]] = None, |
| 170 | + ) -> List[Slice]: |
| 171 | + """Get a list of slices from its name or underlying slice type. |
| 172 | +
|
| 173 | + Parameters: |
| 174 | + name: Name of the desired slice to look up. |
| 175 | + slice_type: Type of slice to look up. This can be one of ('dataset_item', 'object', 'scene') |
| 176 | +
|
| 177 | + Raises: |
| 178 | + NotFound if no slice(s) were found with the given criteria |
| 179 | +
|
| 180 | + Returns: |
| 181 | + :class:`Slice`: The Nucleus slice as an object. |
| 182 | + """ |
| 183 | + endpoint = f"dataset/{self.id}/slices?" |
| 184 | + |
| 185 | + if name is not None: |
| 186 | + endpoint = f"{endpoint}name={name}&" |
| 187 | + |
| 188 | + if slice_type is not None: |
| 189 | + if isinstance(slice_type, str): |
| 190 | + slice_type = SliceType(slice_type) |
| 191 | + |
| 192 | + assert ( |
| 193 | + slice_type in SliceType |
| 194 | + ), f"Slice type ${slice_type} is not valid. Must be one of: {SliceType.options()}" |
| 195 | + endpoint = f"{endpoint}type={slice_type}" |
| 196 | + |
| 197 | + response = self._client.make_request({}, endpoint, requests.get) |
| 198 | + if len(response) == 0: |
| 199 | + errName = f" name={name}" if name is not None else "" |
| 200 | + errType = f"type={slice_type}" if slice_type is not None else "" |
| 201 | + raise NotFoundError( |
| 202 | + f"Slice(s) not found for the parameters:{errName} {errType}" |
| 203 | + ) |
| 204 | + |
| 205 | + return [Slice.from_request(info, self._client) for info in response] |
164 | 206 |
|
165 | 207 | @property |
166 | 208 | def size(self) -> int: |
|
0 commit comments