Closed roomrys closed 1 month ago
The changes in this pull request involve modifications to the SkeletonEncoder
class in the sleap/skeleton.py
file. A new static method, _recursively_sort_dict
, is introduced to sort dictionaries recursively by their keys, which is called within the encode
method to ensure sorted data for backward compatibility with earlier SLEAP versions. Additionally, a test in tests/test_skeleton.py
is updated to verify that the keys in the encoded JSON string are sorted, enhancing the robustness of the encoding process.
File | Change Summary |
---|---|
sleap/skeleton.py | - Added method: _recursively_sort_dict(dictionary: Dict[str, Any]) in SkeletonEncoder . - Updated method: encode(cls, data: Dict[str, Any]) to include sorting step. - Removed unnecessary line for setting jsonpickle options. |
tests/test_skeleton.py | - Updated test_decoded_encoded_Skeleton to assert that keys in the encoded JSON are sorted, including nested dictionaries and lists. |
SkeletonEncoder
class in this PR directly relates to the modifications made to the SkeletonEncoder
class in the main PR, as both involve changes to the encoding process within sleap/skeleton.py
.In the land where data hops,
A rabbit sorts and never stops.
With keys aligned in perfect rows,
Compatibility is how it grows!
Encoding magic, swift and bright,
In SLEAP's world, all feels just right! 🐇✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 75.48%. Comparing base (
7ed1229
) to head (3fcff25
). Report is 55 commits behind head on develop.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Description
In #1970, we created our own
SkeletonEncoder
class to move away from usingjsonpickle.encode
. And, while theSkeletonEncoder
paired with theSkeletonDecoder
works perfectly fine, we get some strange behavior when trying to loadSkeleton
jsons across versions of SLEAP (that still usejsonpickle.decode
).The only difference seemed to be the ordering of the keys in the dictionaries; thus, this PR sorts the
Skeleton
dictionaries before encoding them - which has proven to do the trick with some manual testing across versions.Unsorted skeleton (breaks backwards compatibility)
Sorted skeleton (backwards compatible)
v1.3.3 Skeleton
Types of changes
Does this address any currently open issues?
1972
1970
1961
1841
Outside contributors checklist
Thank you for contributing to SLEAP!
:heart:
Summary by CodeRabbit