Guido van Rossum wrote:
> So then the next question is, what's the use case? What code are people
> writing that may receive either a stdlib container or a numpy array, and
> which needs to do something special if there are no elements? Maybe
> computing the average? AFAICT Tim Hoffman (the OP) never said.

There's two parts to the answer:

1) There functions e.g. in scipy and matplotlib that accept both numpy arrays 
and lists of flows. Speaking from matplotlib experience: While eventually we 
coerce that data to a uniform internal format, there are cases in which we need 
to keep the original data and only convert on a lower internal level. We often 
can return early in a function if there is no data, which is where the 
emptiness check comes in. We have to take extra care to not do the PEP-8 
recommended emptiness check using `if not data`.

2) Even for cases that cannot have different types in the same code, it is 
unsatisfactory that I have to write `if not seq` but `if len(array) == 0` 
depending on the expected data. IMHO whatever the recommended syntax for 
emptiness checking is, it should be the same for lists and arrays and 
dataframes.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/Q6KZEXFLJ6TEFSDQM3SXXIVGNFNURPYT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to