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

2021-08-31 Thread Finn Mason
I've honestly never really used an Enum, so I'm not an expert here. An idea might be using string flags, but setting module level constants equal to the string flag, so that you can use either. For example (using the ipython shell because it's easier in email with quoting and all): In [1]: import

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Steven D'Aprano
On Tue, Aug 31, 2021 at 11:15:22AM -0700, Nick Parlante wrote: > As a practical matter, the IDEs just default to having PEP8 checking on, > and they do it in a very visual way - akin to a text editor which puts > little squiggles under words it thinks are misspelled. > > This maybe sounds annoyin

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Oscar Benjamin
On Wed, 1 Sept 2021 at 01:20, Matthias Bussonnier < bussonniermatth...@gmail.com> wrote: > > Are there other such classes? > [snip] > ... stuff, let's pick a few: > > sympy.physics.optics.Medium: > > def __eq__(self, other): > return self.refractive_index == other.refractive_index > >

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Steven D'Aprano
On Wed, Sep 01, 2021 at 10:29:24AM +1000, Chris Angelico wrote: > In the classic demonstration that 0.1 + 0.2 != 0.3, the problem isn't > equality, it's that none of those values is what you think it is. That is a wonderful way of putting it. -- Steve ___

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Chris Angelico
On Wed, Sep 1, 2021 at 10:23 AM Steven D'Aprano wrote: > What doesn't work, for some definition of "doesn't", is everything > else about floats: addition, subtraction, multiplication, conversion > from decimal, etc. But *equality* is one of the few operations that > works exactly. > Really, the o

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Steven D'Aprano
On Tue, Aug 31, 2021 at 12:35:05PM -0700, Nick Parlante wrote: > You will be relieved to know that we have great fun showing them how == > does not work for floating point numbers. It is super memorable how that > all comes unglued. Of course `==` works for floating point numbers. For floats, `x

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Matthias Bussonnier
> Are there other such classes? from the top of my head, Pandas: In [13]: pd.DataFrame([[1,2], [3, 4]]) == None Out[13]: 0 1 0 False False 1 False False and any zarr container, or xarray will behave like numpy and broadcast. Ah, that means probably Dask, and Ray. Also maybe CuPy

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Nick Parlante
To argue that == is unreliable, I think Matthias has the best, non-contrived example with numpy, which I did not know about: >>> x = np.array([1, 2, 3]) >>> x == None array([False, False, False]) This certainly is a good example of == not being reliable. Point taken there. Are there other such c

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

2021-08-31 Thread Christopher Barker
First: I started this specifically in the context of the stats package and the NaN handling flag, but it did turn into a ore general discussion of Enums, so a final thought: On Tue, Aug 31, 2021 at 4:17 AM Ronald Oussoren wrote: > > Not just static typing, but static analysis in general. Tools

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Christopher Barker
Nick, On teh one hand, I teach a lot of beginners, and I share most of your experience with PEP8 and linters -- indeed, I encourage my studetns to use a linter right off the bat. (I don't require a particular editor, but I do provide recommendations for a handful of common ones (PyCharm, VS Code,

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

2021-08-31 Thread Christopher Barker
On Tue, Aug 31, 2021 at 12:09 AM Stephen J. Turnbull < stephenjturnb...@gmail.com> wrote: > *sigh* __members__ is just the mechanism. As a consequence, Enums are > iterable, and they automatically DTRT with dir() and help() even if > there are no docstrings. but you didn't say dir(), you said _

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Todd
On Tue, Aug 31, 2021, 17:24 Nick Parlante wrote: > Hi Chris - well maybe we're looking at different questions. Your examples > show it is possible to construct a data type where == None does not work. > Clearly that is possible. > > 1. One conclusion is that the possibility of such == means that

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread David Mertz, Ph.D.
If it is not 100% obvious, I would strongly advice any IDE or linter against disabling E711 as a default. I'm not a contributors to any of those, so it's not my decision. But were anyone to ask me... Moreover, I would strongly discourage any instructor from papering over the difference between eq

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Michael Lee
Another idea -- have you considered deferring teaching students about None until after they've had a chance to learn about writing custom objects and operator overloading? None is primarily useful for representing the absence of some value, and I'm not sure if that's something beginners actually n

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Nick Parlante
Hi Chris - well maybe we're looking at different questions. Your examples show it is possible to construct a data type where == None does not work. Clearly that is possible. 1. One conclusion is that the possibility of such == means that in general the == None form is unreliable. This is the prope

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Chris Angelico
On Wed, Sep 1, 2021 at 6:06 AM Nick Parlante wrote: > Is there anyone other than me who would like to push for "== None tolerant" > carve out for non-Python-implementation code? What you're asking is: Is there anyone other than you who would prefer for Python to officially encourage people to wr

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Nick Parlante
Thanks to everyone for many thoughtful comments. I'm going to try to wrap this up. So I talked above about how the IDEs have this very visual way of nudging beginning students to write their code to conform to PEP8, and this is the IDE default. Mostly this is a great, constructive dynamic, nudging

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Chris Angelico
On Wed, Sep 1, 2021 at 5:35 AM Nick Parlante wrote: >> >> > I want to get to a world that is, let's say, "== tolerant" ... >> >> Do you use floating point values in your course? > > > You will be relieved to know that we have great fun showing them how == does > not work for floating point numbe

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Nick Parlante
> > > I want to get to a world that is, let's say, "== tolerant" ... > > Do you use floating point values in your course? You will be relieved to know that we have great fun showing them how == does not work for floating point numbers. It is super memorable how that all comes unglued. Best, Ni

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread 2QdxY4RzWzUUiLuE
On 2021-08-31 at 11:15:22 -0700, Nick Parlante wrote: > As mentioned, PEP8 is formally for narrow cases, and includes > disclaimers about not applying it mechanically, reflecting a basic > reasonableness. Nothing to complain about there. > As a practical matter, the IDEs just default to having

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Todd
On Tue, Aug 31, 2021 at 2:18 PM Nick Parlante wrote: > Hi Steven, I wish I could blame this on zealots, so let me talk a little > bit about how PEP8 works in education, and I'll talk about moving forward > in another message. > > As mentioned, PEP8 is formally for narrow cases, and includes discl

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Nick Parlante
Hi Steven, I wish I could blame this on zealots, so let me talk a little bit about how PEP8 works in education, and I'll talk about moving forward in another message. As mentioned, PEP8 is formally for narrow cases, and includes disclaimers about not applying it mechanically, reflecting a basic re

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread David Mertz, Ph.D.
There doesn't SEEM to be any way to get a non-singleton None in Python 1.0 % python Python 1.0.1 (Jul 15 2016) Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam >>> x = None >>> type(x) >>> id(None) 6587488 >>> y = None >>> x is y 1 >>> id(x) 6587488 Restarting the interpreter, I eve

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Richard Damon
> On Aug 31, 2021, at 9:52 AM, Calvin Spealman wrote: > >  > I think the provenance of the "is None" rule comes from before None was a > guaranteed singleton. In older versions of Python, it was possible to > instantiate more instances of None. So it was possible for "x == None" to > fail ev

[Python-ideas] Re: PEP8 mandatory-is rule

2021-08-31 Thread Calvin Spealman
I think the provenance of the "is None" rule comes from before None was a guaranteed singleton. In older versions of Python, it was *possible* to instantiate more instances of None. So it was possible for "x == None" to fail even if x was *a* None. While the community is very used to and invested

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

2021-08-31 Thread Ricky Teachey
On Tue, Aug 31, 2021 at 9:17 AM Ricky Teachey wrote: > Can someone explain why enum-vs-string is being discussed as if it is an > either-or choice? Why not just call the enum class using the input so that > you can supply a string or enum?I understand this would not be a really > great choice for

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

2021-08-31 Thread Ricky Teachey
Can someone explain why enum-vs-string is being discussed as if it is an either-or choice? Why not just call the enum class using the input so that you can supply a string or enum? NanChoice(nan_choice_input) I understand this would not be a really great choice for a flags enum or int enum, but f

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

2021-08-31 Thread Chris Angelico
On Tue, Aug 31, 2021 at 9:51 PM Steven D'Aprano wrote: > > I want to (in iPython) do: > > > > statistics.median? > > > > and see everything I need to know to use it > > > Okay, so if the API is (say) this: > > def median(data, *, nans='ignore'): > ... > > > will iPython give you a list

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

2021-08-31 Thread Steven D'Aprano
On Mon, Aug 30, 2021 at 10:37:28PM -0700, Christopher Barker wrote: > On Mon, Aug 30, 2021 at 10:22 AM Stephen J. Turnbull < > stephenjturnb...@gmail.com> wrote: > > > Christopher Barker writes: > > > > > e.g.: what are the valid values? > > > > That's easy: MyEnum.__members__. > > > > Seriously

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

2021-08-31 Thread Ronald Oussoren via Python-ideas
> On 30 Aug 2021, at 18:19, Christopher Barker wrote: > > On Mon, Aug 30, 2021 at 12:57 AM Ronald Oussoren > wrote: > > On 28 Aug 2021, at 07:14, Christopher Barker > > wrote: >> >> Also +1 on a string flag, rather than an Enum. > ou