Please consider adding numbers.Boolean
I'm just curious if there was a reason why Boolean was omitted from the numeric tower in the numbers library? It seems that builtins.bool and numpy.bool_ would both be elements of Boolean, and Boolean itself would be Integral? Best, Neil
On 22/06/20 12:19 pm, Neil Girdhar wrote:
I'm just curious if there was a reason why Boolean was omitted from the numeric tower in the numbers library?
Python's bool type is a subclass of int for historical reasons, not because it's conceptually a numeric type. Doing arithmetic on it doesn't really make mathematical sense. -- Greg
I disagree that doing arithmetic on boolean variables doesn't make sense.
Indicator variables which take a value of either zero are one are extremely
common. Dirac or Kronecker delta functions are also examples of functions
where it arithmetically makes sense to talk about values in the boolean
domain. Of course that does mean that you define True as 1 and False as 0,
but that is a very standard convention and it is the case in Python.
I don't have a strong opinion on the proposal itself, but saying
"arithmetic on booleans doesn't doesn't make mathematical sense" is False.
On Mon, Jun 22, 2020 at 5:08 AM Greg Ewing
On 22/06/20 12:19 pm, Neil Girdhar wrote:
I'm just curious if there was a reason why Boolean was omitted from the numeric tower in the numbers library?
Python's bool type is a subclass of int for historical reasons, not because it's conceptually a numeric type. Doing arithmetic on it doesn't really make mathematical sense.
-- Greg _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CMDSMD... Code of Conduct: http://python.org/psf/codeofconduct/
-- -Dr. Jon Crall (him)
On 6/21/2020 8:19 PM, Neil Girdhar wrote:
I'm just curious if there was a reason why Boolean was omitted from the numeric tower in the numbers library? It seems that builtins.bool and numpy.bool_ would both be elements of Boolean, and Boolean itself would be Integral?
Is this being proposed for completeness, or is there some actual problem that would be solved by adding this? Eric
[Neil Girdhar]
It seems that builtins.bool and numpy.bool_ would both be elements of Boolean
I'd be wary of trying to abstract over `bool` and `numpy.bool_`. There are some fundamental differences: - `bool` subclasses `int`; `numpy.bool_` is not a subclass of any integer type - moreover, `numpy.bool_` isn't considered integer-like. It _does_ currently support `__index__`, but that support is deprecated, so at some point in the future a `numpy.bool_` may not be usable in many of the contexts that a Python bool is. (cf https://bugs.python.org/issue37980) - some bitwise operations behave differently: `~False` is not equal to `~np.False_`, and similarly for `True` What's the motivation for this? Is this intended primarily for use in type annotations, or did you have some other use in mind? -- Mark
22.06.20 03:19, Neil Girdhar пише:
I'm just curious if there was a reason why Boolean was omitted from the numeric tower in the numbers library? It seems that builtins.bool and numpy.bool_ would both be elements of Boolean, and Boolean itself would be Integral?
The abstract class for booleans is useless, because all objects can be used in boolean context, and all boolean operations (and, or, not) work with arbitrary objects. So Boolean would be identical to objects.
On Mon, Jun 22, 2020 at 10:19 AM Serhiy Storchaka
The abstract class for booleans is useless, because all objects can be used in boolean context, and all boolean operations (and, or, not) work with arbitrary objects. So Boolean would be identical to objects.
I'm highly ambivalent about Python's model of "Truthiness" -- it's really convenient often, but also gives me a lack of control. So I think it would be helpful, in static type checking cases in particular to say something HAS to be a Bool, and only a Bool. And in that context, I don't think I'd want allow integers. Also, in the reverse, I would wan't folks to be able to use Bools when an integer or other number is expected. So in short: no, Bool should not be considered a Numeric "type" -CHB
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RUQBDQ... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
participants (7)
-
Christopher Barker
-
Eric V. Smith
-
Greg Ewing
-
Jonathan Crall
-
Mark Dickinson
-
Neil Girdhar
-
Serhiy Storchaka