GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: np.testing.assert_allclose does not work if argument is empty iterable · Issue #27457 · numpy/numpy

BUG: np.testing.assert_allclose does not work if argument is empty iterable #27457

New issue
Copy link
New issue
Copy link
Closed
Closed
BUG: np.testing.assert_allclose does not work if argument is empty iterable#27457
Copy link
Labels
00 - Bug

Description

@unalmis
unalmis
opened on Sep 23, 2024
Issue body actions

Describe the issue:

title

Reproduce the code example:

a = 3 # make this anything you want
np.testing.assert_allclose(a, [])

Error message:

No response

Python and NumPy Versions:

See #27413

Runtime Environment:

See #27413

Context for the issue:

This is misleading for this to pass.

This is docstring

Raises an AssertionError if two objects are not equal up to desired tolerance. Given two array_like objects, check that their shapes and all elements are equal (but see the Notes for the special handling of a scalar). An exception is raised if the shapes mismatch or any values conflict. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions.

Activity

  1. unalmis
    added
    00 - Bug
    on Sep 23, 2024
  2. WarrenWeckesser commented on Sep 23, 2024

    @WarrenWeckesser
    WarrenWeckesser
    on Sep 23, 2024
    Member
    More actions

    a is a scalar, and the quoted docstring says but see the Notes for the special handling of a scalar. In the Notes (with Numpy version >= 2.0.0), it is explained that

        When one of `actual` and `desired` is a scalar and the other is
        array_like, the function performs the comparison as if the scalar were
        broadcasted to the shape of the array.
        This behaviour can be disabled with the `strict` parameter.
    

    The second argument in your example, [], is "array_like", and when a scalar (shape ()) is broadcast with an array with shape (0,), the result is an array with shape (0,). So nothing is actually tested, and the assertion is trivially true.

    I wouldn't mind if we deprecated and eventually removed this handling of scalars, but for now, this is an API wart that users need to be aware of. Use the parameter strict=True to avoid it (if you are using NumPy 2.0 or later).

  3. unalmis commented on Sep 23, 2024

    @unalmis
    unalmis
    on Sep 23, 2024
    Author
    More actions

    Ok thanks. I'd suggest either change this or emphasize this example in the docstring.

  4. timhoffm
    added 2 commits that reference this issue on Jun 7, 2025

    DOC: Document assertion comparison behavior between scalar and empty …

    This issue will close once commit 6a26499 is merged into the 'main' branch.
    6a26499

    DOC: Document assertion comparison behavior between scalar and empty …

    This issue will close once commit f8204f5 is merged into the 'main' branch.
    f8204f5
  5. joy2myself
    added a commit that references this issue on Jul 21, 2025

    ENH: Convert unary from C universal intrinsics to C++ using Highway (#19

    3f5dccf
  6. IndifferentArea
    added a commit that references this issue on Dec 7, 2025

    DOC: Document assertion comparison behavior between scalar and empty …

    028a68a
  7. InessaPawson commented on Sep 18, 2026

    @InessaPawson
    InessaPawson
    on Sep 18, 2026
    Member
    More actions

    The behavior was documented in #29143. Closing as fixed.

  8. InessaPawson
    closed this as completedon Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.