This repository was archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Updated docstrings and added in nested code #1
Open
raphaeljafriLB
wants to merge
1
commit into
main
Choose a base branch
from
using_processing_subdirectory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| from labelbox.schema.data_row_metadata import DataRowMetadata, DataRowMetadataKind, DataRowMetadataOntology, DeleteDataRowMetadata | ||
|
|
||
| def __sync_metadata_fields_as_strings(client, metadata_names=[]): | ||
| """ Ensures Labelbox's Metadata Ontology has all necessary metadata fields given a list of names - this script will always sycn metadata fields as strings | ||
| Args: | ||
| client : Required (labelbox.Client) : Labelbox client object | ||
| metadata_names : Required (list) : List of metadata field names to sync with Labelbox | ||
| Returns: | ||
| Updated Labelbox metadata ontology object | ||
| """ | ||
| lb_mdo = client.get_data_row_metadata_ontology() | ||
| lb_metadata_names = [field['name'] for field in lb_mdo._get_ontology()] | ||
| metadata_names += ['lb_integration_source'] | ||
| # Iterate over your metadata_index, if a metadata_index key is not an existing metadata_field, then create it in Labelbox | ||
| for metadata_name in metadata_names: | ||
| if metadata_name not in lb_metadata_names: | ||
| lb_mdo.create_schema(name=metadata_name, kind=DataRowMetadataKind.string) | ||
| lb_mdo = client.get_data_row_metadata_ontology() | ||
| lb_metadata_names = [field['name'] for field in lb_mdo._get_ontology()] | ||
| return lb_mdo | ||
|
|
||
| def __get_metadata_schema_to_name_key( | ||
| lb_mdo:DataRowMetadataOntology | ||
| ): | ||
| """ Creates a dictionary where {key=metadata_schema_id: value=metadata_name_key} | ||
| - name_key is name for all metadata fields, and for enum options, it is "parent_name>>child_name" | ||
| Args: | ||
| lb_mdo : Required (labelbox.schema.data_row_metadata.DataRowMetadataOntology) - Labelbox metadata ontology | ||
| Returns: | ||
| Dictionary where {key=metadata_schema_id: value=metadata_name_key} | ||
| """ | ||
| lb_metadata_dict = lb_mdo.reserved_by_name | ||
| lb_metadata_dict.update(lb_mdo.custom_by_name) | ||
| metadata_schema_to_name_key = {} | ||
| for metadata_field_name in lb_metadata_dict: | ||
| if type(lb_metadata_dict[metadata_field_name]) == dict: | ||
| metadata_schema_to_name_key[lb_metadata_dict[metadata_field_name][next(iter(lb_metadata_dict[metadata_field_name]))].parent] = str(metadata_field_name) | ||
| for enum_option in lb_metadata_dict[metadata_field_name]: | ||
| metadata_schema_to_name_key[lb_metadata_dict[metadata_field_name][enum_option].uid] = f"{str(metadata_field_name)}///{str(enum_option)}" | ||
| else: | ||
| metadata_schema_to_name_key[lb_metadata_dict[metadata_field_name].uid] = str(metadata_field_name) | ||
| return metadata_schema_to_name_key | ||
|
|
||
| def __delete_data_row_metadata( | ||
| lb_mdo:DataRowMetadataOntology, | ||
| data_row_ids:list, metadata_field_names:list, metadata_name_key_to_schema:dict | ||
| ): | ||
| """ Deletes metadata values from a given set of data rows given a list of metadata field names | ||
| Args: | ||
| lb_mdo : Required (labelbox.schema.data_row_metadata.DataRowMetadataOntology) - Labelbox metadata ontology | ||
| data_row_ids : Required (dict) : List of data row IDs to delete metadata from | ||
| metadata_field_names : Required (list) : List of metadata schemas to delete for each data row | ||
| metadata_name_key_to_schema : Required (dict) : Dictionary where {key=metadata_schema_id: value=metadata_name_key} | ||
| Returns: | ||
| True | ||
| """ | ||
| if 'lb_integration_source' in metadata_field_names: | ||
| metadata_field_names.remove('lb_integration_source') | ||
| schemas_to_delete = [metadata_name_key_to_schema[name] for name in metadata_field_names] | ||
| for data_row_id in data_row_ids: | ||
| lb_mdo.bulk_delete([ | ||
| DeleteDataRowMetadata( | ||
| data_row_id = data_row_id, | ||
| fields = schemas_to_delete | ||
| ) | ||
| ]) | ||
| return True |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple new lines here may throw off the autocomplete functions of some editors.