Skip to content

Fix data-dependent flip_array dtype check in all add_* methods#103

Merged
cmutel merged 1 commit into
mainfrom
fix/flip-dtype-check
Jun 4, 2026
Merged

Fix data-dependent flip_array dtype check in all add_* methods#103
cmutel merged 1 commit into
mainfrom
fix/flip-dtype-check

Conversation

@cmutel
Copy link
Copy Markdown
Member

@cmutel cmutel commented Jun 4, 2026

Summary

  • In add_persistent_vector, add_persistent_array, add_dynamic_vector, and add_dynamic_array, the WrongDatatype check on flip_array was nested inside if flip_array.sum(): — so a non-bool flip array with all-zero/falsy values silently passed validation, while the identical dtype with any truthy value raised an error
  • Also fixes add_dynamic_array's early-exit pre-clearing (if not flip_array.sum(): flip_array = None), which discarded a non-bool all-zeros array without ever checking its dtype
  • Fix: hoist the dtype check to the top of the if flip_array is not None: block in all four methods, before the sum() guard that decides whether to write the resource

Test plan

  • Four new regression tests (test_add_*_flip_dtype_all_zeros) covering the previously-silent all-zeros non-bool case for each affected method
  • All existing flip dtype and shape-mismatch tests continue to pass
  • Full test_datapackage.py suite: 54 passed

In add_persistent_vector, add_persistent_array, add_dynamic_vector, and
add_dynamic_array the WrongDatatype check on flip_array was nested inside
`if flip_array.sum():`, so a non-bool flip array with all-zero/falsy values
silently passed validation while the same dtype with any truthy value raised
an error. The validity of an array's dtype must not depend on its contents.

Fix: hoist the dtype check to the top of the `if flip_array is not None:`
block in all four methods, before the sum() guard that decides whether to
write the resource. Also fix add_dynamic_array's early-exit pre-clearing
logic (`if not flip_array.sum(): flip_array = None`) to validate dtype
before discarding the array.

Adds four regression tests covering the previously-silent all-zeros case
for each of the four affected methods.
@cmutel cmutel merged commit f670077 into main Jun 4, 2026
6 checks passed
@cmutel cmutel deleted the fix/flip-dtype-check branch June 4, 2026 08:18
@cmutel cmutel mentioned this pull request Jun 4, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant