Should np.round, np.floor, np.ceil require dimensionless arguments? #1854
TAU-Reinier
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently,
np.round
,np.floor
, andnp.ceil
work according to thematching_input_copy_units_output_ufuncs
rule, meaning the output unit matches the input unit:However, the same Quantity can give a different result:
It gets more unpredictable in cases such as:
which gives axis length 1000 instead of 500 because
int(np.ceil(Q_(0.5, 'second/millisecond'))) == int(Q_(1.0, 'second/millisecond')) == 1000
Moreover, the behavior of
np.ceil
andnp.floor
differ frommath.ceil
andmath.floor
:Should
np.floor
andnp.ceil
, and possiblynp.round
, require dimensionless arguments likemath.ceil
andmath.floor
do?I would argue yes, because I expect
a == b
to implyfunc(a) == func(b)
for all three of these, andQ_(2.0, 'ms') == Q_(0.002, 'sec')
isTrue
.Moreover, I would argue that something like
floor(1.2345 m)
isn't meaningful, because what is thefloor()
of a distance or length? I realize a possible use case would be an engineer who can only order parts in millimeter increments. But I think requiring the explicitnp.floor(Q_(1.2345, 'm').m_as('mm'))
, as well as throwing an error onnp.floor(Q_(1.2345, 'm'))
, can prevent disastrous errors!It looks to me like simply moving "round", "floor", and "ceil" from
matching_input_copy_units_output_ufuncs
toset_units_ufuncs
would do it, though this would be a breaking change.Beta Was this translation helpful? Give feedback.
All reactions