[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2020-08-25 Thread lizardlizard
lizardlizard added the comment: I found this bug searching after noticing weird behaviour in an error message saying sorted expects the reverse flag to be an integer, after it rejected None. This is very surprising. Why isn't it just casting the reverse parameter using bool() to discover

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-10-11 Thread Thomas Caswell
Thomas Caswell added the comment: Any update on resolving this? -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-09-05 Thread Ryan May
Change by Ryan May : -- nosy: +Ryan May ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-09-02 Thread Ralf Gommers
Change by Ralf Gommers : -- nosy: +ralf.gommers ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-30 Thread Sebastian Berg
Sebastian Berg added the comment: I applaud the stricter rules in general, as Mark noted nicely, the issue is that `__index__` is maybe a strange way to achieve that for bools (it is not like `123` is a clean bool)? `__nonzero__` coerces to bools, there is no `__bool__` to convert to bool

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-30 Thread Mark Dickinson
Mark Dickinson added the comment: Victor > The purpose of the DeprecationWarning is to give time to numpy developers to > update the bool_() type, before it becomes an error. No, that's not what's happening: currently, np.bool_ *does* support __index__. In the future, it won't. The NumPy

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-30 Thread STINNER Victor
STINNER Victor added the comment: > DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to > be interpreted as an index That sounds like an issue in numpy: np.bool_ should define the __index__() method, no? $ python3 Python 3.7.4 (default, Jul 9 2019, 16:32:37) >>>

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See more general issue issue15999. -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-30 Thread Mark Dickinson
Mark Dickinson added the comment: Since this particular issue is about "sort", I'm adding Tim and Raymond to the nosy list. -- nosy: +rhettinger, tim.peters ___ Python tracker

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-30 Thread Mark Dickinson
Mark Dickinson added the comment: Yes, I think there's a lot of history here that obscures the picture. We have mechanisms in Python to allow 3rd party objects to be interpreted as floats (via __float__) or as integers (via __index__). So np.int64 (for example) doesn't subclass int (on

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Ammar Askar
Ammar Askar added the comment: Thanks for the insight Terry. I think the functions that accept ints as bools are kind of a red herring: Booleans were only formally introduced in Python 2.3 [1], thus any functions that existed before that accepted ints and continued to accept ints for

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Terry J. Reedy
Terry J. Reedy added the comment: PR-11952 was written by Serhiy and reviewed by Victor (and Mark). They are better qualified to comment on its intended side effects than I am. In the case of sorting, the exception for, say, "reverse='a'", says the flag must be an 'integer' since at least

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Thomas Caswell
Change by Thomas Caswell : -- components: +Library (Lib) versions: +Python 3.9 ___ Python tracker ___ ___ Python-bugs-list mailing

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Sebastian Berg
Change by Sebastian Berg : -- nosy: +seberg ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Mark Dickinson
Mark Dickinson added the comment: Closely related: #37427. I'm not sure why that issue was closed. My naive expectation would be that in most cases where an API specifies a flag, an arbitrary Python object can be used for that flag (and is then interpreted in boolean context). That's the

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Thomas Caswell
Thomas Caswell added the comment: xref numpy issue https://github.com/numpy/numpy/issues/14397 -- ___ Python tracker ___ ___

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Thomas Caswell
Change by Thomas Caswell : Added file: https://bugs.python.org/file48570/test.py ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Thomas Caswell
Change by Thomas Caswell : Added file: https://bugs.python.org/file48569/python_bisect.sh ___ Python tracker ___ ___ Python-bugs-list

[issue37980] regression when passing numpy bools to sorted(..., reverse=r)

2019-08-29 Thread Thomas Caswell
New submission from Thomas Caswell : In python37, numpy1.17 the following runs without warning. import numpy as np sorted([1, 2], reverse=np.bool_(True)) with python38 this emits a DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to be interpreted as an index I