8000 BUG: Type casting with numpy scalars violate promotion rules · Issue #20323 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
BUG: Type casting with numpy scalars violate promotion rules #20323
Closed
@ChristianReinbold

Description

@ChristianReinbold

Describe the issue:

Implicit type casting for binary operators seems to ignore types of scalar values, see code example below where the left operand is passed a 0D scalar and 1D array respectively.

This behaviour provokes unexpected overflow errors in corner cases of empty shape tuples that can be easily overseen.

Reproduce the code example:

import numpy as np
type_w_scalar = (np.ones((), dtype=np.int32) + np.ones(5, dtype=np.int16)).dtype
type_wo_scalar = (np.ones(1, dtype=np.int32) + np.ones(5, dtype=np.int16)).dtype
promoted_type = np.promote_types(np.int32, np.int16)
# Note that promoted_type == type_wo_scalar != type_w_scalar
# promoted_type == np.int32
# type_wo_scalar == np.int32
# type_w_scalar == np.int16
print(type_w_scalar, type_wo_scalar, promoted_type)

Error message:

No response

NumPy/Python version information:

1.20.3 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0