Repository: numpy/numpy
File: numpy/testing/_private/utils.py (Python)

Code before:
        # flag as it everywhere, so we should return the scalar flag.
        # np.ma.masked is also handled and converted to np.False_ (even if the other
        # array has nans/infs etc.; that's OK given the handling later of fully-masked
        # results).
        if isinstance(x_id, bool) or x_id.ndim == 0:
            return np.bool(x_id)
        elif isinstance(y_id, bool) or y_id.ndim == 0:
            return np.bool(y_id)
        else:
            return y_id

    def assert_same_inf_values(x, y, infs_mask):
        """
        Verify all inf values match in the two arrays
        """
        __tracebackhide__ = True  # Hide traceback for py.test

        if not infs_mask.any():
            return
        if x.ndim > 0 and y.ndim > 0:
            x = x[infs_mask]
            y = y[infs_mask]
        else:
            assert infs_mask.all()

        # For details on the work-arounds employed here, see func_assert_same_pos above
        result = x == y
        if not hasattr(result, "all") or not callable(result.all):
            result = np.bool(result)
        if result.all() != True:
            msg = build_err_msg(
                [x, y],
                err_msg + '\ninf values mismatch:',
                verbose=verbose, header=header,
                names=names,
                precision=precision)
            raise AssertionError(msg)

    try:
        if strict:
            cond = x.shape == y.shape and x.dtype == y.dtype
        else:
            cond = (x.shape == () or y.shape == ()) or x.shape == y.shape
        if not cond:
            if x.shape != y.shape:
                reason = f'\n(shapes {x.shape}, {y.shape} mismatch)'
            else:
                reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)'
            msg = build_err_msg([x, y],
                                err_msg
                                + reason,

Review comment (suggestion):
Might it be worth factoring out these two functions? They seem identical except for the part that gets added to `err_msg`.

Code after:
                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.
        # np.ma.masked is also handled and converted to np.False_ (even if the other
        # array has nans/infs etc.; that's OK given the handling later of fully-masked
        # results).
        if isinstance(x_id, bool) or x_id.ndim == 0:
            return np.bool(x_id)
        elif isinstance(y_id, bool) or y_id.ndim == 0:
            return np.bool(y_id)
        else:
            return y_id

    def assert_same_inf_values(x, y, infs_mask):
        """
        Verify all inf values match in the two arrays
        """
        __tracebackhide__ = True  # Hide traceback for py.test

        if not infs_mask.any():
            return
        if x.ndim > 0 and y.ndim > 0:
            x = x[infs_mask]
            y = y[infs_mask]
        else:
            assert infs_mask.all()

        if robust_any_difference(x, y):
            msg = build_err_msg(
                [x, y],
                err_msg + '\ninf values mismatch:',
                verbose=verbose, header=header,
                names=names,
                precision=precision)
            raise AssertionError(msg)

    try:
        if strict:
            cond = x.shape == y.shape and x.dtype == y.dtype
        else:
            cond = (x.shape == () or y.shape == ()) or x.shape == y.shape
        if not cond:
            if x.shape != y.shape:
                reason = f'\n(shapes {x.shape}, {y.shape} mismatch)'
            else:
                reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)'
            msg = build_err_msg([x, y],
                                err_msg
                                + reason,
                                verbose=verbose, header=header,