Skip to content

fix array equality comparison - #394

Merged
wpbonelli merged 3 commits into
modflowpy:developfrom
wpbonelli:fix/array-equality
Oct 3, 2026
Merged

wpbonelli merged 3 commits into
modflowpy:developfrom
wpbonelli:fix/array-equality

Conversation

@wpbonelli

@wpbonelli wpbonelli commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Comparing components with arrays raised an error because the __eq__ method generated by attrs used numpy elementwise comparison, which returns an array instead of a bool. Compare arrays with a new array_eq function instead:

  • shape and dtype must match
  • nans in the same position count as equal (float and complex arrays only)
  • dicts, such as time-array series, are compared key by key
  • dask arrays are not computed, two dask arrays are equal if their shape, dtype, chunks and graph name match
  • a dask array never equals a numpy array

wpbonelli and others added 3 commits October 3, 2026 05:49
attrs' generated __eq__ hit numpy's elementwise == on array fields, so
comparing any two components with arrays raised. Array fields now
compare with array_eq: shape and dtype must match, NaNs at the same
position are equal, and dask arrays are compared by graph name without
being computed. spec.field() applies it to any field with a shape.

Gwf.output holds a back-reference to its model and made model equality
recurse forever, so it no longer takes part in comparison.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Inline arrays like auxiliary have no shape for field() to key on, so
codegen emits eq=ARRAY_EQ for fields converted with to_array. Add a test
that every array-typed field uses a non-default comparer, and update the
Disv equality test for the DFN-shaped vertices and cell2d.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The hook lived in _ml_field, which is never called with a converter,
so regenerating dropped eq=ARRAY_EQ from inline to_array fields. Move it
to filters.field_call and regenerate, which also covers maw/sfr/uzf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wpbonelli wpbonelli added this to the MVP milestone Oct 3, 2026
@wpbonelli wpbonelli added the bug Something isn't working label Oct 3, 2026
@wpbonelli
wpbonelli marked this pull request as ready for review October 3, 2026 13:04
@wpbonelli
wpbonelli merged commit fd3dc57 into modflowpy:develop Oct 3, 2026
16 checks passed
@wpbonelli
wpbonelli deleted the fix/array-equality branch October 3, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant