Skip to content

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

Merged
charris merged 1 commit intonumpy:masterfrom
cgohlke:patch-1
Dec 4, 2020
Merged

BUG: 'bool' object has no attribute 'ndim'#17907
charris merged 1 commit intonumpy:masterfrom
cgohlke:patch-1

Conversation

@cgohlke
Copy link
Copy Markdown
Contributor

@cgohlke cgohlke commented Dec 3, 2020

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 changed the title Fix AttributeError: 'bool' object has no attribute 'ndim' BUG: 'bool' object has no attribute 'ndim' Dec 3, 2020
@charris charris added 09 - Backport-Candidate PRs tagged should be backported component: numpy.testing labels Dec 3, 2020
@charris charris added this to the 1.19.5 release milestone Dec 3, 2020
@charris charris merged commit 45840ad into numpy:master Dec 4, 2020
@charris
Copy link
Copy Markdown
Member

charris commented Dec 4, 2020

Thanks Christoph.

@charris charris modified the milestones: 1.19.5 release, 1.20.0 release Dec 4, 2020
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Dec 4, 2020
@charris charris removed this from the 1.20.0 release milestone Dec 4, 2020
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