Skip to content

Commit 9d64b9d

Browse files
committed
SK-1758 Add detect support in Python SDK
- Fix inconsistencies in detect Python SDK
1 parent b221244 commit 9d64b9d

File tree

6 files changed

+16
-42
lines changed

6 files changed

+16
-42
lines changed

skyflow/client/skyflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def __add_vault_config(self, config):
191191
"detect_controller": Detect(vault_client)
192192
}
193193
log_info(SkyflowMessages.Info.VAULT_CONTROLLER_INITIALIZED.value.format(config.get("vault_id")), self.__logger)
194+
log_info(SkyflowMessages.Info.DETECT_CONTROLLER_INITIALIZED.value.format(config.get("vault_id")), self.__logger)
194195

195196
def __add_connection_config(self, config):
196197
validate_connection_config(self.__logger, config)

skyflow/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from ._skyflow_messages import SkyflowMessages
33
from ._version import SDK_VERSION
44
from ._helpers import get_base_url, format_scope
5-
from ._utils import get_credentials, get_vault_url, construct_invoke_connection_request, get_metrics, parse_insert_response, handle_exception, parse_update_record_response, parse_delete_response, parse_detokenize_response, parse_tokenize_response, parse_query_response, parse_get_response, parse_invoke_connection_response, validate_api_key, encode_column_values, parse_deidentify_text_response, parse_reidentify_text_response, convert_to_entity_type, convert_detected_entity_to_entity_info
5+
from ._utils import get_credentials, get_vault_url, construct_invoke_connection_request, get_metrics, parse_insert_response, handle_exception, parse_update_record_response, parse_delete_response, parse_detokenize_response, parse_tokenize_response, parse_query_response, parse_get_response, parse_invoke_connection_response, validate_api_key, encode_column_values, parse_deidentify_text_response, parse_reidentify_text_response, convert_detected_entity_to_entity_info

skyflow/utils/_utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ def to_lowercase_keys(dict):
8585

8686
return result
8787

88-
def convert_to_entity_type(detect_entities):
89-
entity_types = None
90-
if (detect_entities is not None and len(detect_entities) != 0):
91-
entity_types = []
92-
for entity in detect_entities:
93-
entity_types.append(entity.value)
94-
return entity_types
95-
9688
def convert_detected_entity_to_entity_info(detected_entity):
9789
return EntityInfo(
9890
token=detected_entity.token,

skyflow/vault/controller/_detect.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from skyflow.generated.rest.types.transformations import Transformations
44
from skyflow.generated.rest.types.transformations_shift_dates import TransformationsShiftDates
55
from skyflow.utils._skyflow_messages import SkyflowMessages
6-
from skyflow.utils._utils import convert_to_entity_type, get_metrics, handle_exception, parse_deidentify_text_response, parse_reidentify_text_response
6+
from skyflow.utils._utils import get_metrics, handle_exception, parse_deidentify_text_response, parse_reidentify_text_response
77
from skyflow.utils.constants import SKY_META_DATA_HEADER
88
from skyflow.utils.logger import log_info, log_error_log
99
from skyflow.utils.validations._validations import validate_deidentify_text_request, validate_reidentify_text_request
@@ -26,23 +26,23 @@ def __get_headers(self):
2626

2727
def ___build_deidentify_text_body(self, request: DeidentifyTextRequest) -> Dict[str, Any]:
2828
deidentify_text_body = {}
29-
parsed_entity_types = convert_to_entity_type(request.entities)
29+
parsed_entity_types = request.entities
3030

3131
parsed_token_type = None
3232
if request.token_format is not None:
3333
parsed_token_type = TokenType(
3434
default = request.token_format.default,
35-
vault_token = convert_to_entity_type(request.token_format.vault_token),
36-
entity_unq_counter = convert_to_entity_type(request.token_format.entity_unique_counter),
37-
entity_only = convert_to_entity_type(request.token_format.entity_only)
35+
vault_token = request.token_format.vault_token,
36+
entity_unq_counter = request.token_format.entity_unique_counter,
37+
entity_only = request.token_format.entity_only
3838
)
3939
parsed_transformations = None
4040
if request.transformations is not None:
4141
parsed_transformations = Transformations(
4242
shift_dates = TransformationsShiftDates(
43-
max_days = request.transformations.shift_days.max,
44-
min_days = request.transformations.shift_days.min,
45-
entity_types = convert_to_entity_type(request.transformations.shift_days.entities)
43+
max_days = request.transformations.shift_dates.max,
44+
min_days = request.transformations.shift_dates.min,
45+
entity_types = request.transformations.shift_dates.entities
4646
)
4747
)
4848

@@ -57,9 +57,9 @@ def ___build_deidentify_text_body(self, request: DeidentifyTextRequest) -> Dict[
5757

5858
def ___build_reidentify_text_body(self, request: ReidentifyTextRequest) -> Dict[str, Any]:
5959
parsed_format = ReidentifyStringRequestFormat(
60-
redacted=convert_to_entity_type(request.redacted_entities),
61-
masked=convert_to_entity_type(request.masked_entities),
62-
plaintext=convert_to_entity_type(request.plain_text_entities)
60+
redacted=request.redacted_entities,
61+
masked=request.masked_entities,
62+
plaintext=request.plain_text_entities
6363
)
6464
reidentify_text_body = {}
6565
reidentify_text_body['text'] = request.text
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from skyflow.vault.detect._date_transformation import DateTransformation
22

33
class Transformations:
4-
def __init__(self, shift_days: DateTransformation):
5-
self.shift_days = shift_days
4+
def __init__(self, shift_dates: DateTransformation):
5+
self.shift_dates = shift_dates

tests/utils/test__utils.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
parse_insert_response, parse_update_record_response, parse_delete_response, parse_get_response, \
1212
parse_detokenize_response, parse_tokenize_response, parse_query_response, parse_invoke_connection_response, \
1313
handle_exception, validate_api_key, encode_column_values, parse_deidentify_text_response, \
14-
parse_reidentify_text_response, convert_to_entity_type, convert_detected_entity_to_entity_info
14+
parse_reidentify_text_response, convert_detected_entity_to_entity_info
1515
from skyflow.utils._utils import parse_path_params, to_lowercase_keys, get_metrics
1616
from skyflow.utils.enums import EnvUrls, Env, ContentType
1717
from skyflow.vault.connection import InvokeConnectionResponse
@@ -481,25 +481,6 @@ def test_parse_reidentify_text_response(self):
481481

482482
self.assertEqual(result.processed_text, "Reidentified text with actual values")
483483

484-
def test_convert_to_entity_type_with_valid_entities(self):
485-
"""Test converting entity types with valid input."""
486-
from skyflow.utils.enums import DetectEntities
487-
488-
detect_entities = [DetectEntities.EMAIL_ADDRESS, DetectEntities.PHONE_NUMBER]
489-
result = convert_to_entity_type(detect_entities)
490-
491-
self.assertEqual(result, ["email_address", "phone_number"])
492-
493-
def test_convert_to_entity_type_with_empty_list(self):
494-
"""Test converting entity types with empty list."""
495-
result = convert_to_entity_type([])
496-
self.assertIsNone(result)
497-
498-
def test_convert_to_entity_type_with_none(self):
499-
"""Test converting entity types with None input."""
500-
result = convert_to_entity_type(None)
501-
self.assertIsNone(result)
502-
503484
def test__convert_detected_entity_to_entity_info(self):
504485
"""Test converting detected entity to EntityInfo object."""
505486
mock_detected_entity = Mock()

0 commit comments

Comments
 (0)