[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Steven D'Aprano
On Thu, Aug 26, 2021 at 12:44:18PM +0200, Marc-Andre Lemburg wrote: > Fair enough. Would it then make sense to at least have all possible > NAN objects compare equal, treating the extra error information as an > attribute value rather than a distinct value and perhaps exposing this > as such ? >

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Chris Angelico
On Fri, Aug 27, 2021 at 1:15 PM Finn Mason wrote: > > > Is this too magical? > > result = run('cat file.txt') | run('sort) | run('grep hello', > > capture_output=True, text=True).stdout > > Interesting idea, especially overloading the union/pipe operator (|). I like > it a lot. It reminds me of

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Finn Mason
> Is this too magical? > result = run('cat file.txt') | run('sort) | run('grep hello', capture_output=True, text=True).stdout Interesting idea, especially overloading the union/pipe operator (|). I like it a lot. It reminds me of pathlib.Path (which is a wonderful tool), with its slash operator

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Jeremiah Paige
On Thu, Aug 26, 2021 at 5:53 AM Evan Greenup via Python-ideas < python-ideas@python.org> wrote: > Currently, when what to execute external command, either os.system() or > subprocess functions should be invoked. > > However, it is not so convenient, it would be nice to use "``" symbol to > brace

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread David Mertz, Ph.D.
On Thu, Aug 26, 2021, 6:46 AM Marc-Andre Lemburg > Fair enough. Would it then make sense to at least have all possible NAN > objects compare equal, treating the extra error information as an attribute > value rather than a distinct value and perhaps exposing this as such ? > No, no, no! Almost

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Tim Hoffmann via Python-ideas
And also IPython: https://ipython.readthedocs.io/en/stable/interactive/shell.html e.g. ls_lines = !ls -l ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Random832
On Thu, Aug 26, 2021, at 08:50, Evan Greenup via Python-ideas wrote: > Currently, when what to execute external command, either os.system() or > subprocess functions should be invoked. > > However, it is not so convenient, it would be nice to use "``" symbol > to brace the shell command inside.

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Marc-Andre Lemburg
On 26.08.2021 17:36, Christopher Barker wrote: > There have been a number of discussions on this list, and at least one PEP, > about NaN (and other special values).  > > Let’s keep this thread about handling them in the statistics lib. > > But briefly: > > NaNs are weird on purpose, and Python

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Brendan Barnwell
On 2021-08-23 20:53, Steven D'Aprano wrote: So I propose that statistics functions gain a keyword only parameter to specify the desired behaviour when a NAN is found: - raise an exception - return NAN - ignore it (filter out NANs) which seem to be the three most common preference. (It seems

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Christopher Barker
There have been a number of discussions on this list, and at least one PEP, about NaN (and other special values). Let’s keep this thread about handling them in the statistics lib. But briefly: NaNs are weird on purpose, and Python should absolutely not deviate from IEEE. That’s (one reason)

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Christopher Barker
> There is a Python library called plumbum that provides a shell-like DSL > for executing shell commands: Also xonch: https://xon.sh Python itself is purposely not designed to provide quick and easy shell access. -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting -

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Angus Hollands
There is a Python library called plumbum that provides a shell-like DSL for executing shell commands: https://plumbum.readthedocs.io/en/latest/ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-26 Thread Finn Mason
Tim, you're right. I'm sorry. When this was first posted, I was sure it would be resolved quickly and easily. I very badly communicated that. On Thu, Aug 26, 2021, 12:59 AM Tim Hoffmann wrote: > Hi Finn, > > as a personal feedback: I perceive this comment as disrespectful and not > welcoming.

[Python-ideas] Re: synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Thomas Grainger
subprocess.run(args, capture_output=True, check=True, text=True, encoding="utf8").stdout ? On Thu, 26 Aug 2021, 13:55 Evan Greenup via Python-ideas, < python-ideas@python.org> wrote: > Currently, when what to execute external command, either os.system() or > subprocess functions should be

[Python-ideas] synatx sugar for quickly run shell command and return stdout of shell command as string result

2021-08-26 Thread Evan Greenup via Python-ideas
Currently, when what to execute external command, either os.system() or subprocess functions should be invoked. However, it is not so convenient, it would be nice to use "``" symbol to brace the shell command inside. like: stdout_result_str = `cat file.txt | sort | grep hello` Its is

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Marc-Andre Lemburg
On 26.08.2021 12:15, Steven D'Aprano wrote: > On Thu, Aug 26, 2021 at 11:05:01AM +0200, Marc-Andre Lemburg wrote: > >> Oh, good point. I was under the impression that NAN is handled >> as a singleton. > > There are 4503599627370496 distinct quiet NANs (plus about the same > signalling NANs). So

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Steven D'Aprano
On Wed, Aug 25, 2021 at 10:40:59PM -0700, Christopher Barker wrote: > On Wed, Aug 25, 2021 at 5:39 PM Finn Mason wrote: > > > Or the NaNs could be treated as zeros and a warning raised: > > > > Absolutely not! NaN in no way means zero, ever. We should never provide a > known incorrect result.

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Steven D'Aprano
On Thu, Aug 26, 2021 at 11:05:01AM +0200, Marc-Andre Lemburg wrote: > Oh, good point. I was under the impression that NAN is handled > as a singleton. There are 4503599627370496 distinct quiet NANs (plus about the same signalling NANs). So it would need to be 4-quadrillion-ton :-) (If anyone

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Marc-Andre Lemburg
On 26.08.2021 10:02, Peter Otten wrote: > On 26/08/2021 09:36, Marc-Andre Lemburg wrote: > >> In Python you can use a simple test for this: > > I think you need math.isnan(). > > nan = float('nan') > l = [1,2,3,nan] > d = {nan:1, 2:3, 4:5, 5:nan} > s = set(l) > nan in l >>

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Mark Dickinson
Returning a NaN by default has the advantage of being consistent with IEEE 754 semantics for sequence-based operations (like `sum` and `dot`) and with existing Python `math` module functions like `fsum`, `prod` and `hypot`. In IEEE 754, the majority of operations silently return a NaN (not

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Peter Otten
On 26/08/2021 09:36, Marc-Andre Lemburg wrote: In Python you can use a simple test for this: I think you need math.isnan(). nan = float('nan') l = [1,2,3,nan] d = {nan:1, 2:3, 4:5, 5:nan} s = set(l) nan in l True That only works with identical nan-s, and because the container omits the

[Python-ideas] Re: NAN handling in statistics functions

2021-08-26 Thread Marc-Andre Lemburg
On 26.08.2021 02:36, Finn Mason wrote: > Perhaps a warning could be raised but the NaNs are ignored. For example: > > Input: statistics.mean([4, 2, float('nan')]) > Output: [warning blah blah blah] > 3 > > Or the NaNs could be treated as zeros and a warning raised: > > Input: