FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

BUG: Shouldn't numpy's floating types (e.g. `np.float_`) and python's native `float` type be compatible? · Issue #23663 · numpy/numpy · GitHub

/ numpy Public

BUG: Shouldn't numpy's floating types (e.g. np.float_) and python's native float type be compatible? #23663

Description

Describe the issue:

When trying to type hint functions accepting scalars, I get unexpected error messages from my type checker (Pylance). As np.float_ is a subtype of python's native float type, I would expect to be able to pass a variable with type np.float_ when a native float is expected.

Reproduce the code example:

import numpy as np

def idx(x: float) -> float:
    return x

arr = np.arange(5.0, dtype=np.float_)
sum = np.sum(arr)
idx(sum)

Error message:

Argument of type "float_" cannot be assigned to parameter "x" of type "float" in function "idx"
  "float_" is incompatible with "float" Pylance (reportGeneralTypeIssues)

Runtime information:

1.24.1
3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0]
WARNING: threadpoolctl not found in system! Install it by pip install threadpoolctl. Once installed, try np.show_runtime again for more detailed build information
[{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}}]
None

Context for the issue:

This issue makes it either impossible or much harder to correctly type hint functions such that they are compatible with numpy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL