Skip to content

Commit 994dc17

Browse files
Merge pull request #1987 from kili-technology/feature/lab-4081-aau-i-can-use-the-is-not-operator-on-status-step-assignee
feat(LAB-4081): aau i can use the is not operator on status step assignee
2 parents fc42598 + 211507c commit 994dc17

File tree

5 files changed

+182
-74
lines changed

5 files changed

+182
-74
lines changed

src/kili/adapters/kili_api_gateway/asset/mappers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,7 @@ def asset_where_mapper(filters: AssetFilters):
6565
"status": filters.issue_status,
6666
},
6767
"stepIdIn": filters.step_id_in,
68+
"stepIdNotIn": filters.step_id_not_in,
6869
"stepStatusIn": filters.step_status_in,
70+
"stepStatusNotIn": filters.step_status_not_in,
6971
}

src/kili/domain/asset/asset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,20 @@ class AssetFilters:
6363
skipped: Optional[bool] = None
6464
status_in: Optional[ListOrTuple[AssetStatus]] = None
6565
step_id_in: Optional[ListOrTuple[str]] = None
66+
step_id_not_in: Optional[ListOrTuple[str]] = None
6667
step_status_in: Optional[ListOrTuple[StatusInStep]] = None
68+
step_status_not_in: Optional[ListOrTuple[StatusInStep]] = None
6769

6870

69-
class AssetWorkflowFilters(TypedDict):
71+
class AssetWorkflowFilters(TypedDict, total=False):
7072
"""Asset filters relative to worklow."""
7173

7274
skipped: Optional[bool]
7375
status_in: Optional[ListOrTuple[AssetStatus]]
7476
step_name_in: Optional[ListOrTuple[str]]
77+
step_name_not_in: Optional[ListOrTuple[str]]
7578
step_status_in: Optional[ListOrTuple[StatusInStep]]
79+
step_status_not_in: Optional[ListOrTuple[StatusInStep]]
7680

7781

7882
def get_asset_default_fields(

src/kili/domain_api/assets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ class AssetFilter(TypedDict, total=False):
8888
skipped: Optional[bool]
8989
status_in: Optional[list[AssetStatus]]
9090
step_name_in: Optional[list[str]]
91+
step_name_not_in: Optional[list[str]]
9192
step_status_in: Optional[list[StatusInStep]]
93+
step_status_not_in: Optional[list[StatusInStep]]
9294
updated_at_gte: Optional[str]
9395
updated_at_lte: Optional[str]
9496

src/kili/presentation/client/asset.py

Lines changed: 122 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,55 @@
4343
import pandas as pd
4444

4545

46+
def _warn_deprecated_gt_lt_args(
47+
consensus_mark_gt: Optional[float],
48+
consensus_mark_lt: Optional[float],
49+
honeypot_mark_gt: Optional[float],
50+
honeypot_mark_lt: Optional[float],
51+
label_consensus_mark_gt: Optional[float],
52+
label_consensus_mark_lt: Optional[float],
53+
label_created_at_gt: Optional[str],
54+
label_created_at_lt: Optional[str],
55+
label_honeypot_mark_gt: Optional[float],
56+
label_honeypot_mark_lt: Optional[float],
57+
) -> None:
58+
"""Warn about deprecated _gt and _lt arguments."""
59+
for arg_name, arg_value in zip(
60+
(
61+
"consensus_mark_gt",
62+
"consensus_mark_lt",
63+
"honeypot_mark_gt",
64+
"honeypot_mark_lt",
65+
"label_consensus_mark_gt",
66+
"label_consensus_mark_lt",
67+
"label_created_at_gt",
68+
"label_created_at_lt",
69+
"label_honeypot_mark_gt",
70+
"label_honeypot_mark_lt",
71+
),
72+
(
73+
consensus_mark_gt,
74+
consensus_mark_lt,
75+
honeypot_mark_gt,
76+
honeypot_mark_lt,
77+
label_consensus_mark_gt,
78+
label_consensus_mark_lt,
79+
label_created_at_gt,
80+
label_created_at_lt,
81+
label_honeypot_mark_gt,
82+
label_honeypot_mark_lt,
83+
),
84+
strict=False,
85+
):
86+
if arg_value:
87+
warnings.warn(
88+
f"'{arg_name}' is deprecated, please use"
89+
f" '{arg_name.replace('_gt', '_gte').replace('_lt', '_lte')}' instead.",
90+
DeprecationWarning,
91+
stacklevel=2,
92+
)
93+
94+
4695
@for_all_methods(log_call, exclude=["__init__"])
4796
class AssetClientMethods(BaseClientMethods):
4897
"""Methods attached to the Kili client, to run actions on assets."""
@@ -108,7 +157,9 @@ def assets(
108157
skipped: Optional[bool] = None,
109158
status_in: Optional[list[AssetStatus]] = None,
110159
step_name_in: Optional[list[str]] = None,
160+
step_name_not_in: Optional[list[str]] = None,
111161
step_status_in: Optional[list[StatusInStep]] = None,
162+
step_status_not_in: Optional[list[StatusInStep]] = None,
112163
*,
113164
as_generator: Literal[True],
114165
) -> Generator[dict, None, None]:
@@ -174,7 +225,9 @@ def assets(
174225
skipped: Optional[bool] = None,
175226
status_in: Optional[list[AssetStatus]] = None,
176227
step_name_in: Optional[list[str]] = None,
228+
step_name_not_in: Optional[list[str]] = None,
177229
step_status_in: Optional[list[StatusInStep]] = None,
230+
step_status_not_in: Optional[list[StatusInStep]] = None,
178231
*,
179232
as_generator: Literal[False] = False,
180233
) -> list[dict]:
@@ -240,7 +293,9 @@ def assets(
240293
skipped: Optional[bool] = None,
241294
status_in: Optional[list[AssetStatus]] = None,
242295
step_name_in: Optional[list[str]] = None,
296+
step_name_not_in: Optional[list[str]] = None,
243297
step_status_in: Optional[list[StatusInStep]] = None,
298+
step_status_not_in: Optional[list[StatusInStep]] = None,
244299
*,
245300
as_generator: bool = False,
246301
) -> Union[Iterable[dict], "pd.DataFrame"]:
@@ -312,8 +367,13 @@ def assets(
312367
Only applicable if the project is in the WorkflowV1 (legacy).
313368
step_name_in: Returned assets are in the step whose name belong to that list, if given.
314369
Only applicable if the project is in WorkflowV2.
370+
step_name_not_in: Returned assets are in the step whose name does not belong to that list, if given.
371+
Only applicable if the project is in WorkflowV2.
315372
step_status_in: Returned assets have the status in their step that belongs to that list, if given.
316373
Only applicable if the project is in WorkflowV2.
374+
step_status_not_in: Returned assets have the status in their step that does not belong to that list, if given.
375+
Possible choices: `TO_DO`, `DOING`, `PARTIALLY_DONE`, `REDO`, `DONE`, `SKIPPED`.
376+
Only applicable if the project is in WorkflowV2.
317377
318378
!!! info "Dates format"
319379
Date strings should have format: "YYYY-MM-DD"
@@ -374,40 +434,18 @@ def assets(
374434
stacklevel=1,
375435
)
376436

377-
for arg_name, arg_value in zip(
378-
(
379-
"consensus_mark_gt",
380-
"consensus_mark_lt",
381-
"honeypot_mark_gt",
382-
"honeypot_mark_lt",
383-
"label_consensus_mark_gt",
384-
"label_consensus_mark_lt",
385-
"label_created_at_gt",
386-
"label_created_at_lt",
387-
"label_honeypot_mark_gt",
388-
"label_honeypot_mark_lt",
389-
),
390-
(
391-
consensus_mark_gt,
392-
consensus_mark_lt,
393-
honeypot_mark_gt,
394-
honeypot_mark_lt,
395-
label_consensus_mark_gt,
396-
label_consensus_mark_lt,
397-
label_created_at_gt,
398-
label_created_at_lt,
399-
label_honeypot_mark_gt,
400-
label_honeypot_mark_lt,
401-
),
402-
strict=False,
403-
):
404-
if arg_value:
405-
warnings.warn(
406-
f"'{arg_name}' is deprecated, please use"
407-
f" '{arg_name.replace('_gt', '_gte').replace('_lt', '_lte')}' instead.",
408-
DeprecationWarning,
409-
stacklevel=1,
410-
)
437+
_warn_deprecated_gt_lt_args(
438+
consensus_mark_gt=consensus_mark_gt,
439+
consensus_mark_lt=consensus_mark_lt,
440+
honeypot_mark_gt=honeypot_mark_gt,
441+
honeypot_mark_lt=honeypot_mark_lt,
442+
label_consensus_mark_gt=label_consensus_mark_gt,
443+
label_consensus_mark_lt=label_consensus_mark_lt,
444+
label_created_at_gt=label_created_at_gt,
445+
label_created_at_lt=label_created_at_lt,
446+
label_honeypot_mark_gt=label_honeypot_mark_gt,
447+
label_honeypot_mark_lt=label_honeypot_mark_lt,
448+
)
411449

412450
disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm)
413451

@@ -430,26 +468,36 @@ def assets(
430468
)
431469

432470
step_id_in = None
433-
if (
434-
step_name_in is not None
435-
or step_status_in is not None
471+
step_id_not_in = None
472+
has_step_filters = step_name_in is not None or step_name_not_in is not None
473+
has_status_filters = (
474+
step_status_in is not None
475+
or step_status_not_in is not None
436476
or status_in is not None
437477
or skipped is not None
438-
):
478+
)
479+
if has_step_filters or has_status_filters:
439480
check_asset_workflow_arguments(
440481
project_workflow_version=project_workflow_version,
441482
asset_workflow_filters={
442483
"skipped": skipped,
443484
"status_in": status_in,
444485
"step_name_in": step_name_in,
486+
"step_name_not_in": step_name_not_in,
445487
"step_status_in": step_status_in,
488+
"step_status_not_in": step_status_not_in,
446489
},
447490
)
448491
if project_workflow_version == "V2" and step_name_in is not None:
449492
step_id_in = extract_step_ids_from_project_steps(
450493
project_steps=project_steps,
451494
step_name_in=step_name_in,
452495
)
496+
if project_workflow_version == "V2" and step_name_not_in is not None:
497+
step_id_not_in = extract_step_ids_from_project_steps(
498+
project_steps=project_steps,
499+
step_name_in=step_name_not_in,
500+
)
453501

454502
asset_use_cases = AssetUseCases(self.kili_api_gateway)
455503
filters = AssetFilters(
@@ -495,7 +543,9 @@ def assets(
495543
issue_status=issue_status,
496544
issue_type=issue_type,
497545
step_id_in=step_id_in,
546+
step_id_not_in=step_id_not_in,
498547
step_status_in=step_status_in,
548+
step_status_not_in=step_status_not_in,
499549
)
500550
assets_gen = asset_use_cases.list_assets(
501551
filters,
@@ -568,7 +618,9 @@ def count_assets(
568618
external_id_strictly_in: Optional[list[str]] = None,
569619
external_id_in: Optional[list[str]] = None,
570620
step_name_in: Optional[list[str]] = None,
621+
step_name_not_in: Optional[list[str]] = None,
571622
step_status_in: Optional[list[StatusInStep]] = None,
623+
step_status_not_in: Optional[list[StatusInStep]] = None,
572624
) -> int:
573625
# pylint: disable=line-too-long
574626
"""Count and return the number of assets with the given constraints.
@@ -627,9 +679,14 @@ def count_assets(
627679
For example, with `external_id_in=['abc']`, any asset with an external id containing `'abc'` will be returned.
628680
step_name_in: Returned assets are in a step whose name belong to that list, if given.
629681
Only applicable if the project is in WorkflowV2.
682+
step_name_not_in: Returned assets are in a step whose name does not belong to that list, if given.
683+
Only applicable if the project is in WorkflowV2.
630684
step_status_in: Returned assets have the status of their step that belongs to that list, if given.
631685
Possible choices: `TO_DO`, `DOING`, `PARTIALLY_DONE`, `REDO`, `DONE`, `SKIPPED`.
632686
Only applicable if the project is in WorkflowV2.
687+
step_status_not_in: Returned assets have the status of their step that does not belong to that list, if given.
688+
Possible choices: `TO_DO`, `DOING`, `PARTIALLY_DONE`, `REDO`, `DONE`, `SKIPPED`.
689+
Only applicable if the project is in WorkflowV2.
633690
634691
!!! info "Dates format"
635692
Date strings should have format: "YYYY-MM-DD"
@@ -658,43 +715,26 @@ def count_assets(
658715
stacklevel=1,
659716
)
660717

661-
for arg_name, arg_value in zip(
662-
(
663-
"consensus_mark_gt",
664-
"consensus_mark_lt",
665-
"honeypot_mark_gt",
666-
"honeypot_mark_lt",
667-
"label_consensus_mark_gt",
668-
"label_consensus_mark_lt",
669-
"label_created_at_gt",
670-
"label_created_at_lt",
671-
"label_honeypot_mark_gt",
672-
"label_honeypot_mark_lt",
673-
),
674-
(
675-
consensus_mark_gt,
676-
consensus_mark_lt,
677-
honeypot_mark_gt,
678-
honeypot_mark_lt,
679-
label_consensus_mark_gt,
680-
label_consensus_mark_lt,
681-
label_created_at_gt,
682-
label_created_at_lt,
683-
label_honeypot_mark_gt,
684-
label_honeypot_mark_lt,
685-
),
686-
strict=False,
687-
):
688-
if arg_value:
689-
warnings.warn(
690-
f"'{arg_name}' is deprecated, please use"
691-
f" '{arg_name.replace('_gt', '_gte').replace('_lt', '_lte')}' instead.",
692-
DeprecationWarning,
693-
stacklevel=1,
694-
)
718+
_warn_deprecated_gt_lt_args(
719+
consensus_mark_gt=consensus_mark_gt,
720+
consensus_mark_lt=consensus_mark_lt,
721+
honeypot_mark_gt=honeypot_mark_gt,
722+
honeypot_mark_lt=honeypot_mark_lt,
723+
label_consensus_mark_gt=label_consensus_mark_gt,
724+
label_consensus_mark_lt=label_consensus_mark_lt,
725+
label_created_at_gt=label_created_at_gt,
726+
label_created_at_lt=label_created_at_lt,
727+
label_honeypot_mark_gt=label_honeypot_mark_gt,
728+
label_honeypot_mark_lt=label_honeypot_mark_lt,
729+
)
695730

696731
step_id_in = None
697-
if status_in is not None or step_name_in is not None or step_status_in is not None:
732+
step_id_not_in = None
733+
has_step_filters = step_name_in is not None or step_name_not_in is not None
734+
has_status_filters = (
735+
status_in is not None or step_status_in is not None or step_status_not_in is not None
736+
)
737+
if has_step_filters or has_status_filters:
698738
project_use_cases = ProjectUseCases(self.kili_api_gateway)
699739
(
700740
project_steps,
@@ -705,7 +745,9 @@ def count_assets(
705745
asset_workflow_filters={
706746
"skipped": skipped,
707747
"step_name_in": step_name_in,
748+
"step_name_not_in": step_name_not_in,
708749
"step_status_in": step_status_in,
750+
"step_status_not_in": step_status_not_in,
709751
"status_in": status_in,
710752
},
711753
)
@@ -715,6 +757,11 @@ def count_assets(
715757
project_steps=project_steps,
716758
step_name_in=step_name_in,
717759
)
760+
if project_workflow_version == "V2" and step_name_not_in is not None:
761+
step_id_not_in = extract_step_ids_from_project_steps(
762+
project_steps=project_steps,
763+
step_name_in=step_name_not_in,
764+
)
718765

719766
filters = AssetFilters(
720767
project_id=ProjectId(project_id),
@@ -759,7 +806,9 @@ def count_assets(
759806
issue_status=issue_status,
760807
issue_type=issue_type,
761808
step_id_in=step_id_in,
809+
step_id_not_in=step_id_not_in,
762810
step_status_in=step_status_in,
811+
step_status_not_in=step_status_not_in,
763812
)
764813
asset_use_cases = AssetUseCases(self.kili_api_gateway)
765814
return asset_use_cases.count_assets(filters)

0 commit comments

Comments
 (0)