Skip to content

BUG: numpy.pad pad constant is cast to input array dtype  #16499

@lkjell

Description

@lkjell

When a constant pad is performed the constant value is cast to the dtype of the input array. This is problematic for dtype int and constant value is float.

Reproducing code example:

import numpy as np

x = np.arange(10)
x = np.pad(x, 1, "constant", constant_values=3.3)
print(x)

x = np.arange(10)
x = np.pad(x, 1, "constant", constant_values=np.nan)
print(x)

Error message:

The expected final array should have the constant value not converted to int.

Numpy/Python version information:

import sys, numpy; print(numpy.version, sys.version)

1.18.1 3.8.3 (default, May 17 2020, 18:15:42)
[GCC 10.1.0]

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