Skip to content

non-quantity constant_values parameter to pad #992

@keewis

Description

@keewis

Passing non-quantity parameters to np.pad in constant mode results in behaviour different from passing dimensionless quantities:

In [1]: import numpy as np 
   ...: import pint 
   ...: ureg = pint.UnitRegistry()

In [2]: a = np.arange(5) * ureg.m

In [3]: np.pad(a, (2, 4), mode="constant", constant_values=4)                                                                                                                                                                   
Out[3]: array([4, 4, 0, 1, 2, 3, 4, 4, 4, 4, 4]) <Unit('meter')>

In [4]: np.pad(a, (2, 4), mode="constant", constant_values=4 * ureg.dimensionless)                                                                                                                                              
DimensionalityError: Cannot convert from 'dimensionless' (dimensionless) to 'meter' ([length])

I'd expect [3] and [4] to be equivalent, but one of the checks in test_pad seems to expect the current behaviour so I'm not sure if this is a misconception on my part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnumpyNumpy related bug/enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions