Skip to content

compare does not work for object arrays #163

Closed

Description

@gdementen

When it contains non numeric data (e.g. strings), the maxdiff is 'nan' and thus, you get no colors.

Worse yet, when it does not contain strings but contains zeros it crashes with ZeroDivisionError because np.seterr(divide='ignore', invalid='ignore') has no effect for object arrays. In effect in that case a / b is mostly equal to calling __truediv__ on each cell and this raises ZeroDivisionError: division by zero

Activity

  1. added this to the 0.30 milestone on Sep 24, 2018
  2. modified the milestones: 0.30, 0.31 on Feb 6, 2019
  3. removed this from the 0.31 milestone on Aug 1, 2019
  4. added this to the 0.35 milestone on Sep 16, 2022
  5. modified the milestones: 0.35, 0.34.2 on Oct 4, 2023
  6. modified the milestones: 0.34.2, 0.35 on Oct 25, 2023
  7. modified the milestones: 0.35, 0.36 on Aug 14, 2025
  8. gdementen commented on Mar 23, 2026

    @gdementen
    CollaboratorAuthor

    Simple test cases:

    >>> arr1 = ndtest(3).astype(object)
    >>> arr2 = ndtest(3).astype(object)
    >>> compare(arr1, arr2)
    <snip>
    File C:\usr\devel\larray-editor\larray_editor\comparator.py:185, in ComparatorWidget._update_from_combined_array(self)
        183 with np.errstate(divide='ignore', invalid='ignore'):
        184     diff = self._combined_array - self._array0
    --> 185     reldiff = diff / self._array0
        186 # make reldiff 0 where the values are the same than array0 even for
        187 # special values (0, nan, inf, -inf)
        188 # at this point reldiff can still contain nan and infs
        189 reldiff = la.where(eq, 0, reldiff)
    ZeroDivisionError: division by zero
    >>> arr1 = ndtest(3).astype(str)
    >>> arr2 = ndtest(3).astype(str)
    >>> compare(arr1, arr2)
  9. modified the milestones: 0.36, 0.35.1 on Mar 23, 2026
  10. added a commit that references this issue on Mar 23, 2026
    59a2912
  11. added a commit that references this issue on Mar 26, 2026
    feb1d1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions