- changed version to 4.1 or higher
Python: boolean operator of dataObject gives an unwanted behaviour
Currently, the bool operator of itom.dataObject gives an unwanted behaviour:
import numpy as np
print(bool(dataObject.zeros([1,]))) # -> True (ERROR)
print(bool(dataObject.ones([1,])))# -> True (OK)
print(bool(dataObject.zeros([2,2])))# -> True (ERROR)
print(bool(dataObject.ones([2,2])))# -> True (ERROR)
print(bool(np.zeros([1,])))# -> False
print(bool(np.ones([1,])))# -> True
print(bool(np.zeros([2,2]))) # -> ValueError
print(bool(np.ones([2,2]))) # -> ValueError
The dataObject should behave like numpy arrays. The bool operator is also used, if the dataObject is used in an if condition.
The desired behaviour is:
- If the dataObject or np.ndarray has one value, the bool operator returns False if the value is 0, else True.
- In any other case, the bool operator return a ValueError with the message The truth value of an array with more than one element is ambiguous.
Currently, the if-condition:
d = dataObject.zeros([1,])
if d:
print("yes")
always had the output yes. This is not logical and has to be changed.
Currently (itom > 3.2.1, but < 4.0), the bool operator of itom.dataObject will raise a temporary warning, saying that the behaviour will change in the future.
Question: When is the right time to change the behaviour to the same behaviour than Numpy? itom 4.0 or later?
Comments (6)
-
reporter -
reporter 2020-04-16: Decision: The old behaviour with the deprecated warning will be kept active (e.g. for the itom setup 4.0) and will be changed to the new behaviour in 6-12 month (with the next official setup)
-
reporter - changed milestone to Version 4.1
- changed version to 4.0
-
reporter - changed milestone to 4.1
-
reporter -
assigned issue to
-
assigned issue to
-
reporter - changed status to resolved
fixes issue
#119and adapts the bool(dataObject) output to the behaviour of numpy.ndarrays.→ <<cset ec81f0c97868>>
- Log in to comment