Skip to content

Commit 7b5ef04

Browse files
Captainiabenieric
authored andcommitted
fix: use different separator to flatten dict (aws#4629)
1 parent c537f97 commit 7b5ef04

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/sagemaker/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ def can_model_package_source_uri_autopopulate(source_uri: str):
16051605
)
16061606

16071607

1608-
def flatten_dict(source_dict: Dict[str, Any], sep: str = ".") -> Dict[str, Any]:
1608+
def flatten_dict(source_dict: Dict[str, Any], sep: str = "^") -> Dict[str, Any]:
16091609
"""Flatten a nested dictionary.
16101610
16111611
Args:
@@ -1620,7 +1620,7 @@ def flatten_dict(source_dict: Dict[str, Any], sep: str = ".") -> Dict[str, Any]:
16201620
return {}
16211621

16221622

1623-
def unflatten_dict(source_dict: Dict[str, Any], sep: str = ".") -> Dict[str, Any]:
1623+
def unflatten_dict(source_dict: Dict[str, Any], sep: str = "^") -> Dict[str, Any]:
16241624
"""Unflatten a flattened dictionary back into a nested dictionary.
16251625
16261626
Args:

tests/unit/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ def test_can_model_package_source_uri_autopopulate():
18191819
class TestDeepMergeDict(TestCase):
18201820
def test_flatten_dict_basic(self):
18211821
nested_dict = {"a": 1, "b": {"x": 2, "y": {"p": 3, "q": 4}}, "c": 5}
1822-
flattened_dict = {"a": 1, "b.x": 2, "b.y.p": 3, "b.y.q": 4, "c": 5}
1822+
flattened_dict = {"a": 1, "b^x": 2, "b^y^p": 3, "b^y^q": 4, "c": 5}
18231823
self.assertDictEqual(flatten_dict(nested_dict), flattened_dict)
18241824
self.assertDictEqual(unflatten_dict(flattened_dict), nested_dict)
18251825

@@ -1837,7 +1837,7 @@ def test_flatten_dict_no_nested(self):
18371837

18381838
def test_flatten_dict_with_various_types(self):
18391839
nested_dict = {"a": [1, 2, 3], "b": {"x": None, "y": {"p": [], "q": ""}}, "c": 9}
1840-
flattened_dict = {"a": [1, 2, 3], "b.x": None, "b.y.p": [], "b.y.q": "", "c": 9}
1840+
flattened_dict = {"a": [1, 2, 3], "b^x": None, "b^y^p": [], "b^y^q": "", "c": 9}
18411841
self.assertDictEqual(flatten_dict(nested_dict), flattened_dict)
18421842
self.assertDictEqual(unflatten_dict(flattened_dict), nested_dict)
18431843

0 commit comments

Comments
 (0)