-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added `from_params` method for models and `model_from_params` function
- Loading branch information
Showing
8 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,42 @@ | ||
from rectools.utils.misc import unflatten_dict | ||
|
||
|
||
class TestUnflattenDict: | ||
def test_empty(self) -> None: | ||
assert unflatten_dict({}) == {} | ||
|
||
def test_complex(self) -> None: | ||
flattened = { | ||
"a.b": 1, | ||
"a.c": 2, | ||
"d": 3, | ||
"a.e.f": [10, 20], | ||
} | ||
excepted = { | ||
"a": {"b": 1, "c": 2, "e": {"f": [10, 20]}}, | ||
"d": 3, | ||
} | ||
assert unflatten_dict(flattened) == excepted | ||
|
||
def test_simple(self) -> None: | ||
flattened = { | ||
"a": 1, | ||
"b": 2, | ||
} | ||
excepted = { | ||
"a": 1, | ||
"b": 2, | ||
} | ||
assert unflatten_dict(flattened) == excepted | ||
|
||
def test_non_default_sep(self) -> None: | ||
flattened = { | ||
"a_b": 1, | ||
"a_c": 2, | ||
"d": 3, | ||
} | ||
excepted = { | ||
"a": {"b": 1, "c": 2}, | ||
"d": 3, | ||
} | ||
assert unflatten_dict(flattened, sep="_") == excepted |