Skip to content

Conversation

@VinciGit00
Copy link
Contributor

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) and offset (array of objects) were silently dropped.

Solution

Modified the is_uniform_array_of_objects() function in toon/utils.py to:

  • Check if all fields in all objects are primitive types
  • Return None if any non-primitive field is found
  • This forces the encoder to use the list array format instead of tabular format

The list array format properly handles nested structures and preserves all data.

Changes

  • toon/utils.py: Enhanced is_uniform_array_of_objects() to detect non-primitive fields
  • tests/test_nested_arrays.py: Added comprehensive test suite with 5 new tests covering:
    • Arrays with nested arrays
    • Arrays with nested objects
    • Mixed primitive and nested fields
    • Complex roundtrip scenarios
    • Partial nested fields

Testing

  • ✅ All 5 new tests pass
  • ✅ All 107 existing tests pass without regression
  • ✅ No linting errors

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

- Modified is_uniform_array_of_objects() to return None when objects contain non-primitive fields
- Arrays with nested objects/arrays now use list format instead of tabular format
- This ensures all data is preserved during encoding/decoding
- Added comprehensive test suite for nested structures
- All 107 existing tests pass without regression

Fixes #6
@VinciGit00 VinciGit00 merged commit c66bf8f into main Nov 13, 2025
2 checks passed
@VinciGit00 VinciGit00 deleted the fix/nested-arrays-issue-6 branch November 13, 2025 14:54
@github-actions
Copy link

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested objects in array lose information on toonification

2 participants