-
Notifications
You must be signed in to change notification settings - Fork 69
add custom dict camelize logic #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+221
−103
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
53810a5
add custom dict camelize logic
DaltheCow cd0d445
fix quality checks
DaltheCow 86d0147
Merge branch 'main' into remove-pyhumps
DaltheCow 8682d10
Merge branch 'main' into remove-pyhumps
sjmonson 3c090cd
Fix formatting + update lock
sjmonson 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
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,23 @@ | ||
def recursive_key_update(d, key_update_func): | ||
if not isinstance(d, dict) and not isinstance(d, list): | ||
return d | ||
|
||
if isinstance(d, list): | ||
for item in d: | ||
recursive_key_update(item, key_update_func) | ||
return d | ||
|
||
updated_key_pairs = [] | ||
for key, _ in d.items(): | ||
updated_key = key_update_func(key) | ||
if key != updated_key: | ||
updated_key_pairs.append((key, updated_key )) | ||
|
||
for key_pair in updated_key_pairs: | ||
old_key, updated_key = key_pair | ||
d[updated_key] = d[old_key] | ||
del d[old_key] | ||
|
||
for _, value in d.items(): | ||
recursive_key_update(value, key_update_func) | ||
return d |
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
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
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
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
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,76 @@ | ||
import pytest | ||
|
||
from guidellm.utils.dict import recursive_key_update | ||
|
||
|
||
def update_str(string): | ||
return string + "_updated" | ||
|
||
@pytest.mark.smoke | ||
def test_recursive_key_update_updates_keys(): | ||
my_dict = { | ||
"my_key": { | ||
"my_nested_key": { | ||
"my_double_nested_key": "someValue" | ||
}, | ||
"my_other_nested_key": "someValue" | ||
}, | ||
"my_other_key": "value" | ||
} | ||
my_updated_dict = { | ||
"my_key_updated": { | ||
"my_nested_key_updated": { | ||
"my_double_nested_key_updated": "someValue" | ||
}, | ||
"my_other_nested_key_updated": "someValue" | ||
}, | ||
"my_other_key_updated": "value" | ||
} | ||
recursive_key_update(my_dict, update_str) | ||
assert my_dict == my_updated_dict | ||
|
||
|
||
def truncate_str_to_ten(string): | ||
return string[:10] | ||
|
||
|
||
@pytest.mark.smoke | ||
def test_recursive_key_update_leaves_unchanged_keys(): | ||
my_dict = { | ||
"my_key": { | ||
"my_nested_key": { | ||
"my_double_nested_key": "someValue" | ||
}, | ||
"my_other_nested_key": "someValue" | ||
}, | ||
"my_other_key": "value" | ||
} | ||
my_updated_dict = { | ||
"my_key": { | ||
"my_nested_": { | ||
"my_double_": "someValue" | ||
}, | ||
"my_other_n": "someValue" | ||
}, | ||
"my_other_k": "value" | ||
} | ||
recursive_key_update(my_dict, truncate_str_to_ten) | ||
assert my_dict == my_updated_dict | ||
|
||
|
||
@pytest.mark.smoke | ||
def test_recursive_key_update_updates_dicts_in_list(): | ||
my_dict = { | ||
"my_key": | ||
[{ "my_list_item_key_1": "someValue" }, | ||
{ "my_list_item_key_2": "someValue" }, | ||
{ "my_list_item_key_3": "someValue" }] | ||
} | ||
my_updated_dict = { | ||
"my_key_updated": | ||
[{ "my_list_item_key_1_updated": "someValue" }, | ||
{ "my_list_item_key_2_updated": "someValue" }, | ||
{ "my_list_item_key_3_updated": "someValue" }] | ||
} | ||
recursive_key_update(my_dict, update_str) | ||
assert my_dict == my_updated_dict |
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,12 @@ | ||
import pytest | ||
|
||
from guidellm.utils.text import camelize_str | ||
|
||
|
||
@pytest.mark.smoke | ||
def test_camelize_str_camelizes_string(): | ||
assert camelize_str("no_longer_snake_case") == "noLongerSnakeCase" | ||
|
||
@pytest.mark.smoke | ||
def test_camelize_str_leaves_non_snake_case_text_untouched(): | ||
assert camelize_str("notsnakecase") == "notsnakecase" |
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.
Uh oh!
There was an error while loading. Please reload this page.