Skip to content

Commit a72b5bb

Browse files
committed
feat(LAB-3532): deprecate metadata_types, add metadata_properties in update_properties_in_project
1 parent 968a44c commit a72b5bb

7 files changed

Lines changed: 91 additions & 18 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def project_where_mapper(filters: ProjectFilters) -> Dict:
2929

3030
def project_data_mapper(data: ProjectDataKiliAPIGatewayInput) -> Dict:
3131
"""Build the GraphQL ProjectData variable to be sent in an operation."""
32-
return {
32+
result = {
3333
"archived": data.archived,
3434
"author": data.author,
3535
"complianceTags": data.compliance_tags,
@@ -42,7 +42,6 @@ def project_data_mapper(data: ProjectDataKiliAPIGatewayInput) -> Dict:
4242
"inputType": data.input_type,
4343
"instructions": data.instructions,
4444
"jsonInterface": data.json_interface,
45-
"metadataTypes": data.metadata_types,
4645
"minConsensusSize": data.min_consensus_size,
4746
"numberOfAssets": data.number_of_assets,
4847
"rules": data.rules,
@@ -55,3 +54,18 @@ def project_data_mapper(data: ProjectDataKiliAPIGatewayInput) -> Dict:
5554
"title": data.title,
5655
"useHoneyPot": data.use_honeypot,
5756
}
57+
58+
if data.metadata_properties is not None:
59+
result["metadataProperties"] = data.metadata_properties
60+
elif data.metadata_types is not None:
61+
metadata_properties = {}
62+
for key, type_value in data.metadata_types.items():
63+
metadata_properties[key] = {
64+
"filterable": True,
65+
"type": type_value,
66+
"visibleByLabeler": True,
67+
"visibleByReviewer": True,
68+
}
69+
result["metadataProperties"] = metadata_properties
70+
71+
return result

src/kili/adapters/kili_api_gateway/project/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ProjectDataKiliAPIGatewayInput:
2525
instructions: Optional[str]
2626
json_interface: Optional[str]
2727
metadata_types: Optional[Dict]
28+
metadata_properties: Optional[Dict]
2829
min_consensus_size: Optional[int]
2930
number_of_assets: Optional[int]
3031
rules: Optional[str]

src/kili/entrypoints/mutations/project/queries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
$instructions: String
2525
$inputType: InputType
2626
$jsonInterface: String
27-
$metadataTypes: JSON
27+
$metadataProperties: JSON
2828
$minConsensusSize: Int
2929
$numberOfAssets: Int
3030
$numberOfSkippedAssets: Int
@@ -50,7 +50,7 @@
5050
instructions: $instructions
5151
inputType: $inputType
5252
jsonInterface: $jsonInterface
53-
metadataTypes: $metadataTypes
53+
metadataProperties: $metadataProperties
5454
minConsensusSize: $minConsensusSize
5555
numberOfAssets: $numberOfAssets
5656
numberOfSkippedAssets: $numberOfSkippedAssets

src/kili/presentation/client/project.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def update_properties_in_project(
304304
title: Optional[str] = None,
305305
use_honeypot: Optional[bool] = None,
306306
metadata_types: Optional[dict] = None,
307+
metadata_properties: Optional[dict] = None,
307308
seconds_to_label_before_auto_assign: Optional[int] = None,
308309
should_auto_assign: Optional[bool] = None,
309310
) -> Dict[str, Any]:
@@ -339,36 +340,59 @@ def update_properties_in_project(
339340
in honeypot or consensus settings
340341
title: Title of the project
341342
use_honeypot: Activate / Deactivate the use of honeypot in the project
342-
metadata_types: Types of the project metadata.
343+
metadata_types: DEPRECATED. Types of the project metadata.
343344
Should be a `dict` of metadata fields name as keys and metadata types as values.
344345
Currently, possible types are: `string`, `number`
346+
metadata_properties: Properties of the project metadata.
347+
Should be a `dict` of metadata fields name as keys and metadata properties as values.
348+
Each property is a dict with the following keys:
349+
- `type`: Type of the metadata. Currently, possible types are: `string`, `number`
350+
- `filterable`: If `True`, the metadata can be used as filters in project queue
351+
- `visibleByLabeler`: If `True`, the metadata is visible one the asset by labelers
352+
- `visibleByReviewer`: If `True`, the metadata is visible one the asset by reviewers
345353
seconds_to_label_before_auto_assign: DEPRECATED, use `should_auto_assign` instead.
346354
should_auto_assign: If `True`, assets are automatically assigned to users when they start annotating.
347355
348356
Returns:
349357
A dict with the changed properties which indicates if the mutation was successful,
350358
else an error message.
351359
352-
!!! example "Change Metadata Types"
353-
Metadata fields are by default interpreted as `string` types. To change the type
354-
of a metadata field, you can use the `update_properties_in_project` function with the
355-
metadata_types argument. `metadata_types` is given as a dict of metadata field names
356-
as keys and metadata types as values.
360+
!!! example "Change Metadata Properties"
361+
Metadata fields are by default interpreted as `string` types and have default properties.
362+
To change the properties of a metadata field, you can use the `update_properties_in_project`
363+
function with the `metadata_properties` argument. `metadata_properties` is given as a dict
364+
of metadata field names as keys and metadata properties as values.
357365
358366
```python
359367
kili.update_properties_in_project(
360368
project_id = project_id,
361-
metadata_types = {
362-
'customConsensus': 'number',
363-
'sensitiveData': 'string',
364-
'uploadedFromCloud': 'string',
365-
'modelLabelErrorScore': 'number'
369+
metadata_properties = {
370+
'customConsensus': {
371+
'filterable': True,
372+
'type': 'number',
373+
'visibleByLabeler': True,
374+
'visibleByReviewer': True,
375+
},
376+
'sensitiveData': {
377+
'filterable': True,
378+
'type': 'string',
379+
'visibleByLabeler': False,
380+
'visibleByReviewer': True,
381+
}
366382
}
367383
)
368384
```
369385
370-
Not providing a type for a metadata field or providing an unsupported one
371-
will default to the `string` type.
386+
Not providing a property or providing an unsupported one will use the default values:
387+
```
388+
filterable: True
389+
type: 'string'
390+
visibleByLabeler: True
391+
visibleByReviewer: True
392+
```
393+
394+
!!! note "Deprecated: Change Metadata Types"
395+
The `metadata_types` parameter is deprecated. Please use `metadata_properties` instead.
372396
"""
373397
if seconds_to_label_before_auto_assign is not None:
374398
warnings.warn(
@@ -378,6 +402,14 @@ def update_properties_in_project(
378402
stacklevel=1,
379403
)
380404

405+
if metadata_types is not None:
406+
warnings.warn(
407+
"metadata_types is going to be deprecated. Please use"
408+
" `metadata_properties` field instead to configure metadata properties.",
409+
DeprecationWarning,
410+
stacklevel=1,
411+
)
412+
381413
return ProjectUseCases(self.kili_api_gateway).update_properties_in_project(
382414
ProjectId(project_id),
383415
can_navigate_between_assets=can_navigate_between_assets,
@@ -400,6 +432,7 @@ def update_properties_in_project(
400432
use_honeypot=use_honeypot,
401433
title=title,
402434
metadata_types=metadata_types,
435+
metadata_properties=metadata_properties,
403436
should_auto_assign=should_auto_assign,
404437
seconds_to_label_before_auto_assign=seconds_to_label_before_auto_assign,
405438
)

src/kili/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class ProjectWithoutDataset(TypedDict, total=False):
153153
interface: Dict
154154
interfaceCompute: Dict
155155
jsonInterface: Dict
156+
metadataProperties: Dict
156157
metadataTypes: Dict
157158
minConsensusSize: int
158159
mlTasks: str

src/kili/use_cases/project/project.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def update_properties_in_project(
127127
title: Optional[str] = None,
128128
use_honeypot: Optional[bool] = None,
129129
metadata_types: Optional[Dict] = None,
130+
metadata_properties: Optional[Dict] = None,
130131
should_auto_assign: Optional[bool] = None,
131132
seconds_to_label_before_auto_assign: Optional[int] = None,
132133
) -> Dict[str, object]:
@@ -146,6 +147,29 @@ def update_properties_in_project(
146147
if should_auto_assign is None and seconds_to_label_before_auto_assign is not None:
147148
should_auto_assign = seconds_to_label_before_auto_assign is not None
148149

150+
# Handle metadata_types deprecation and conversion to metadata_properties
151+
if metadata_types is not None:
152+
if metadata_properties is None:
153+
metadata_properties = {}
154+
for key, type_value in metadata_types.items():
155+
metadata_properties[key] = {
156+
"filterable": True,
157+
"type": type_value,
158+
"visibleByLabeler": True,
159+
"visibleByReviewer": True,
160+
}
161+
162+
if metadata_properties is not None:
163+
for key, properties in metadata_properties.items():
164+
if "filterable" not in properties:
165+
properties["filterable"] = True
166+
if "type" not in properties:
167+
properties["type"] = "string"
168+
if "visibleByLabeler" not in properties:
169+
properties["visibleByLabeler"] = True
170+
if "visibleByReviewer" not in properties:
171+
properties["visibleByReviewer"] = True
172+
149173
project_data = ProjectDataKiliAPIGatewayInput(
150174
can_navigate_between_assets=can_navigate_between_assets,
151175
can_skip_asset=can_skip_asset,
@@ -158,6 +182,7 @@ def update_properties_in_project(
158182
input_type=input_type,
159183
json_interface=json.dumps(json_interface) if json_interface is not None else None,
160184
metadata_types=metadata_types,
185+
metadata_properties=metadata_properties,
161186
min_consensus_size=min_consensus_size,
162187
number_of_assets=number_of_assets,
163188
number_of_skipped_assets=number_of_skipped_assets,

tests/integration/presentation/test_project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def test_when_updating_project_then_it_returns_updated_project(mocker: pytest_mo
6161
"inputType": None,
6262
"instructions": None,
6363
"jsonInterface": None,
64-
"metadataTypes": None,
6564
"minConsensusSize": None,
6665
"numberOfAssets": None,
6766
"rules": None,

0 commit comments

Comments
 (0)