Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TaskAnnotationState and Optimization JobType #312

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions geti_sdk/data_models/enums/job_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class JobType(Enum):
RECONSTRUCT_VIDEO = "reconstruct_video"
EVALUATE = "evaluate"
OPTIMIZATION = "optimization"
OPTIMIZE_POT = "optimize_pot"
OPTIMIZE_NNCF = "optimize_nncf"
TEST = "test"
PREPARE_IMPORT_TO_NEW_PROJECT = "prepare_import_to_new_project"
PERFORM_IMPORT_TO_NEW_PROJECT = "perform_import_to_new_project"
Expand Down
8 changes: 6 additions & 2 deletions geti_sdk/data_models/task_annotation_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
from typing import Optional

import attr

Expand All @@ -26,6 +27,9 @@ class TaskAnnotationState:
"""

task_id: str
state: str = attr.field(
converter=str_to_enum_converter_by_name_or_value(AnnotationState)
state: Optional[str] = attr.field(
converter=str_to_enum_converter_by_name_or_value(
AnnotationState, allow_none=True
),
default=None,
)
5 changes: 4 additions & 1 deletion geti_sdk/data_models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _converter(input_value: Optional[Union[str, EnumType]]) -> Optional[EnumType


def str_to_enum_converter_by_name_or_value(
enum: Type[EnumType],
enum: Type[EnumType], allow_none: bool = False
) -> Callable[[Union[str, EnumType]], EnumType]:
"""
Construct a converter function to convert an input value into an instance of the
Expand All @@ -113,6 +113,7 @@ def str_to_enum_converter_by_name_or_value(
This method attempts to convert both from the Enum value as well as it's name

:param enum: type of the Enum to which the converter should convert
:param allow_none: True to allow `None` as input value, i.e. for optional parameters
:return: Converter function that takes an input value and attempts to convert it
into an instance of `enum`
"""
Expand All @@ -131,6 +132,8 @@ def _converter(input_value: Union[str, EnumType]) -> EnumType:
return enum[input_value]
elif isinstance(input_value, enum):
return input_value
if (input_value is None) and allow_none:
return None
else:
raise ValueError(
f"Invalid argument! Cannot convert value {input_value} to Enum "
Expand Down
Loading