labscript-suite / labscript

The 𝗹𝗮𝗯𝘀𝗰𝗿𝗶𝗽𝘁 library provides a translation from expressive Python code to low-level hardware instructions.
http://labscriptsuite.org
BSD 2-Clause "Simplified" License
9 stars 52 forks source link

Do not use 'is' for numeric literal comparisons #68

Closed rpanderson closed 4 years ago

rpanderson commented 4 years ago

These elicit a SyntaxWarning since Python 3.8 (explanation).

chrisjbillington commented 4 years ago

Sweet. Fixes #56

rpanderson commented 4 years ago

This introduced a bug when arrays[0] is an array.

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
chrisjbillington commented 4 years ago

I've never had a good rule for what to use in this situation. Neither any() or all() is approriate, and we don't want to do a typecheck on it being an int since it's allowed to be float zero as well.

Maybe

if not isinstance(arrays[0], np.ndarray) and arrays[0] == 0:
chrisjbillington commented 4 years ago

Ah,

if np.array_equal(arrays[0], 0):

appears to do the trick

Always returns False for differing shapes, and for scalars is equivalent to ==. I think it's the right solution.