Description
Merging into one issue from #8622 and #9583.
A suggestion sometimes thrown around is to deprecate the following:
bool(np.array([1]))
bool(np.array([0]))
bool(np.array([[[[0]]]]))
Arguments for why we shouldn't allow these:
- they can hide bugs - code like
if arr_1d:
might pass in a test suite, only to fail in production whenlen(arr1d) > 1
, because the user forgot to writearr_1d.all()
- They can trick users into thinking that
if arr_1d
is equivalent toif list_1d
However, this is perhaps too invasive a change. Collecting sentiments from elsewhere:
I can see an argument from purity that this should only happen for 0d arrays; it's a bit ugly and inconsistent with other situations that we're willing to discard shape information here. But this is arguably a practicality beats purity case, and anyway the disruption of trying to change it is wayy not worth it just for a bit of purity.
And I always think 0d arrays -> bool makes sense, but single element is funny ;)
Changing this sort of fundamental semantics (i.e. size-1 arrays behave
like scalars in bool, int, etc. casting context) this late in the game
in my opinion should be discussed with more care.While the intention of making it harder to write code with bugs is good,
it should not come at the cost of having everyone fix their old scripts,
which worked correctly previously, but then suddenly stop working. Note
also that I expect polling on this mailing list will not reach the
majority of the user base, so I would suggest being very conservative
when deprecating features that are not wrong but only with suboptimal
semantics. This sort of backward-incompatible changes accumulate, and
will lead to rotting of third-party code.
I'm not trying to reopen discussion here, but just giving us a place to summarize it.