Fix: Preserve nested arrays and objects in array encoding (Issue #6) #7
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.
Summary
This PR fixes issue #6 where nested objects and arrays within tabular arrays were being lost during the toonification process.
Problem
When encoding arrays of objects that contained non-primitive fields (nested arrays or objects), only the primitive fields were preserved in the tabular format. Non-primitive fields like
hierarchy(array of strings) andoffset(array of objects) were silently dropped.Solution
Modified the
is_uniform_array_of_objects()function intoon/utils.pyto:Noneif any non-primitive field is foundThe list array format properly handles nested structures and preserves all data.
Changes
toon/utils.py: Enhancedis_uniform_array_of_objects()to detect non-primitive fieldstests/test_nested_arrays.py: Added comprehensive test suite with 5 new tests covering:Testing
Trade-offs
While this fix ensures data preservation, arrays with nested fields will now use the list format instead of the more compact tabular format. This is the correct behavior since the tabular format cannot represent nested structures without data loss.
Fixes #6