Skip to content

numpy.__array_namespace_info__().dtypes()["float64"] == None is True but numpy.float64 == None is False #359

Description

@34j

In my understanding, dtype can be any Python object in array API specification, and therefore may be None depending on the library. If the device is somewhat set to None while using numpy backend in array API compatible code, the above specification (numpy/numpy#18434) causes various problems when working with dtypes.

> from array_api_compat import numpy as np
> np.__array_namespace_info__().dtypes()["float64"]
dtype('float64')
> np.float64
<class 'numpy.float64'>
> np.__array_namespace_info__().dtypes()["float64"] == np.float64
True
> np.__array_namespace_info__().dtypes()["float64"] == None
True
> np.float64 == None
False

Activity

  1. rgommers commented on Nov 2, 2025

    @rgommers
    Member

    This is just caused by an oddity in NumPy and it'd be best to fix it there.

    It could be avoided by returning np.float64 instead of np.dtype('float64') here:

    "float64": dtype(float64),

    That would seem to be the most natural choice, not sure why it was implemented like this. Changing it now might give some issues for someone in corner cases though, just like this issue is just a corner case. So I don't know if anything should be done here - "just don't do that" is also a fine answer.

  2. 34j commented on Nov 2, 2025

    @34j
    Author

    >>> info = np.__array_namespace_info__()
    >>> info.dtypes(kind='signed integer')
    {'int8': numpy.int8,
    'int16': numpy.int16,
    'int32': numpy.int32,
    'int64': numpy.int64}

    I just noticed that this doctest is inconsistent with the current behavior (dtype('int8'). ...) by the way

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions