Skip to content

BUG: 'bool' object has no attribute 'ndim'#17918

Merged
charris merged 1 commit intonumpy:maintenance/1.19.xfrom
charris:backport-17907
Dec 4, 2020
Merged

BUG: 'bool' object has no attribute 'ndim'#17918
charris merged 1 commit intonumpy:maintenance/1.19.xfrom
charris:backport-17907

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented Dec 4, 2020

Backport of #17907.

I get the following error in the tifffile tests while comparing large bilevel images using numpy's assert_array_equal function. It looks like a typo.

x = array([[ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
      ...True],
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True]])
y = array([[ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True],
      ...True],
       [ True,  True,  True, ...,  True,  True,  True],
       [ True,  True,  True, ...,  True,  True,  True]])
func = <function assert_array_compare.<locals>.<lambda> at 0x0B085810>, hasval = '+inf'

    def func_assert_same_pos(x, y, func=isnan, hasval='nan'):
        """Handling nan/inf.

        Combine results of running func on x and y, checking that they are True
        at the same locations.

        """
        x_id = func(x)
        y_id = func(y)
        # We include work-arounds here to handle three types of slightly
        # pathological ndarray subclasses:
        # (1) all() on `masked` array scalars can return masked arrays, so we
        #     use != True
        # (2) __eq__ on some ndarray subclasses returns Python booleans
        #     instead of element-wise comparisons, so we cast to bool_() and
        #     use isinstance(..., bool) checks
        # (3) subclasses with bare-bones __array_function__ implementations may
        #     not implement np.all(), so favor using the .all() method
        # We are not committed to supporting such subclasses, but it's nice to
        # support them if possible.
        if bool_(x_id == y_id).all() != True:
            msg = build_err_msg([x, y],
                                err_msg + '\nx and y %s location mismatch:'
                                % (hasval), verbose=verbose, header=header,
                                names=('x', 'y'), precision=precision)
            raise AssertionError(msg)
        # If there is a scalar, then here we know the array has the same
        # flag as it everywhere, so we should return the scalar flag.
        if isinstance(x_id, bool) or x_id.ndim == 0:
            return bool_(x_id)
>       elif isinstance(x_id, bool) or y_id.ndim == 0:
E       AttributeError: 'bool' object has no attribute 'ndim'

@charris charris modified the milestones: 1.19.5 release, 1.20.0 release Dec 4, 2020
@charris charris merged commit b0b9acc into numpy:maintenance/1.19.x Dec 4, 2020
@charris charris deleted the backport-17907 branch December 4, 2020 23:03
@charris charris changed the title Fix AttributeError: 'bool' object has no attribute 'ndim' BUG: Fix AttributeError: 'bool' object has no attribute 'ndim' Jan 5, 2021
@charris charris changed the title BUG: Fix AttributeError: 'bool' object has no attribute 'ndim' BUG: 'bool' object has no attribute 'ndim' Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants