Re: [Python-ideas] slice[] to get more complex slices

2018-07-30 Thread Stephan Hoyer
On Sat, Jul 28, 2018 at 9:44 AM Jonathan Fine wrote: > By all means start a PEP (on github) if you find it helps you. I think > it's too early. > > If this problem has a pure Python solution, then I think it best to > develop it as a third party module. I suggest the name slicetools. > When slice

Re: [Python-ideas] slice[] to get more complex slices

2018-07-28 Thread Jonathan Fine
Hi Stephan I took a look at your personal web site. Your PhD sounds interesting. Quantum coherence and photosynthesis. But off-topic here. (Sadly, personal web sites are a bit of mess.) You wrote: > I'd really like to move this proposal forward in some form. +10 > As a next step, would it be he

Re: [Python-ideas] slice[] to get more complex slices

2018-07-26 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:37 PM David Mertz wrote: > I find pandas.IndexSlice makes a lot of operations easier to spell. As > simple as it is, it's a valuable capability. Rather than every library—or a > number of them anyway—creating the same 4 lines of code with a different > name, it would be

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:19 PM Stefan Behnel wrote: > Stephan Hoyer schrieb am 23.07.2018 um 18:01: > > I think a SliceHelper class like this is a reasonable solution, but there > > would be a lot of value having it a standard place somewhere in the > > standard library (e.g., operator.subscript

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread David Mertz
I find pandas.IndexSlice makes a lot of operations easier to spell. As simple as it is, it's a valuable capability. Rather than every library—or a number of them anyway—creating the same 4 lines of code with a different name, it would be much nicer to have it as a class __getitem__ method, e.g. sli

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Stefan Behnel
Stephan Hoyer schrieb am 23.07.2018 um 18:01: > On Mon, Jul 23, 2018 at 4:24 AM Paul Moore wrote: > >> I thought the reason the proposal got nowhere was because it's pretty >> simple to define it yourself: >> >> >>> class SliceHelper: >> ... def __getitem__(self, slice): >> ... return

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread George Leslie-Waksman
May I propose `slice.L` as in "slice literal": ``` class slice: ... class L: """Slice literal. slice.L[1:2:3, 1] -> (slice(1, 2, 3), slice(1)) """ @classmethod def __class_getitem__(cls, item): return item ``` On Mon, Jul 23, 2018 at 12:02 PM Joseph Jevnik w

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Joseph Jevnik
I still think that 'operator.subscript' would be valuable to me for all of the same reasons discussed in the previous threads and issues. I don't understand why it was reverted without any serious discussion given that it was already accepted and many people find this useful. On Mon, Jul 23, 2018

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Jonathan Fine
Humour warning. Serhiy wrote: > Do you bless using __class_getitem__ for something other than typing? As in https://perldoc.perl.org/functions/bless.html, perhaps? -- Jonathan ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Serhiy Storchaka
23.07.18 18:16, Guido van Rossum пише: On Mon, Jul 23, 2018 at 3:24 AM, Jeroen Demeyer > wrote: On 2018-07-23 11:58, Grégory Lielens wrote: Not sure slice[1::3] can be done It can be done. Since "slice" is a class, it would require a metaclass t

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Jelle Zijlstra
2018-07-23 8:16 GMT-07:00 Guido van Rossum : > On Mon, Jul 23, 2018 at 3:24 AM, Jeroen Demeyer > wrote: > >> On 2018-07-23 11:58, Grégory Lielens wrote: >> >>> Not sure slice[1::3] can be done >>> >> >> It can be done. Since "slice" is a class, it would require a metaclass >> though. >> > > Since

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Stephan Hoyer
On Mon, Jul 23, 2018 at 4:24 AM Paul Moore wrote: > I thought the reason the proposal got nowhere was because it's pretty > simple to define it yourself: > > >>> class SliceHelper: > ... def __getitem__(self, slice): > ... return slice > ... > >>> SH = SliceHelper() > >>> SH[1::3] > s

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Guido van Rossum
On Mon, Jul 23, 2018 at 3:24 AM, Jeroen Demeyer wrote: > On 2018-07-23 11:58, Grégory Lielens wrote: > >> Not sure slice[1::3] can be done >> > > It can be done. Since "slice" is a class, it would require a metaclass > though. > Since PEP 560 it won't need a metaclass -- it can be implemented as

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Todd
On Mon, Jul 23, 2018 at 8:41 AM, Paul Moore wrote: > On 23 July 2018 at 13:19, Todd wrote: > > On Mon, Jul 23, 2018 at 7:24 AM, Paul Moore wrote: > >> > >> On 23 July 2018 at 11:31, Jeroen Demeyer wrote: > >> > On 2018-07-23 12:24, Jeroen Demeyer wrote: > >> >> > >> >> Another solution that no

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Paul Moore
On 23 July 2018 at 13:19, Todd wrote: > On Mon, Jul 23, 2018 at 7:24 AM, Paul Moore wrote: >> >> On 23 July 2018 at 11:31, Jeroen Demeyer wrote: >> > On 2018-07-23 12:24, Jeroen Demeyer wrote: >> >> >> >> Another solution that nobody has mentioned (as far as I know) is to add >> >> additional sy

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Todd
On Mon, Jul 23, 2018 at 7:24 AM, Paul Moore wrote: > On 23 July 2018 at 11:31, Jeroen Demeyer wrote: > > On 2018-07-23 12:24, Jeroen Demeyer wrote: > >> > >> Another solution that nobody has mentioned (as far as I know) is to add > >> additional syntax to the language for that. For example, one

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Todd
On Mon, Jul 23, 2018 at 6:28 AM, Jonathan Fine wrote: > Hi Grégory > > You wrote: > > Oh yes , I see. Seems like almost everybody think using the [...] syntax > to > > define reusable slices is a good idea, > > > Not sure slice[1::3] can be done, but this has my preference too: it's > the > > mos

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Todd
On Mon, Jul 23, 2018 at 6:24 AM, Jeroen Demeyer wrote: > On 2018-07-23 11:58, Grégory Lielens wrote: > >> Not sure slice[1::3] can be done >> > > It can be done. Since "slice" is a class, it would require a metaclass > though. > > Another solution that nobody has mentioned (as far as I know) is t

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Grégory Lielens
That would be even more directbut it require syntax support, usefull mainly for people doing multdim complex slicing (i.e numpy users). I may be wrong, but I do not see it gain much support outside numpy... slice[] is probably much more easy to swallow for standard python users, and alm

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Paul Moore
On 23 July 2018 at 11:31, Jeroen Demeyer wrote: > On 2018-07-23 12:24, Jeroen Demeyer wrote: >> >> Another solution that nobody has mentioned (as far as I know) is to add >> additional syntax to the language for that. For example, one could say >> that (1:3) could be used to construct slice(1, 3)

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Jeroen Demeyer
On 2018-07-23 12:24, Jeroen Demeyer wrote: Another solution that nobody has mentioned (as far as I know) is to add additional syntax to the language for that. For example, one could say that (1:3) could be used to construct slice(1, 3) directly. The parentheses are required to avoid confusion wit

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Jonathan Fine
Hi Grégory You wrote: > Oh yes , I see. Seems like almost everybody think using the [...] syntax to > define reusable slices is a good idea, > Not sure slice[1::3] can be done, but this has my preference too: it's the > most direct exposure I can think of... The slice class already has all the c

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Jeroen Demeyer
On 2018-07-23 11:58, Grégory Lielens wrote: Not sure slice[1::3] can be done It can be done. Since "slice" is a class, it would require a metaclass though. Another solution that nobody has mentioned (as far as I know) is to add additional syntax to the language for that. For example, one co

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Grégory Lielens
Oh yes , I see. Seems like almost everybody think using the [...] syntax to define reusable slices is a good idea, the discussion is where this could be implemented, knowing that numpy.s_ already exists. Discussion is not easy to follow, with the patch almost accepted then delayed then rejected

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Jonathan Fine
Hi Grégory You wrote: > Seems that the initial proposal was skipped just for timing reasons The discussion is in https://bugs.python.org/issue24379. It was first skipped for that reason. Second time around our Then and now Former BDFL wrote === https://bugs.python.org/msg280721 Actually I'm with

Re: [Python-ideas] slice[] to get more complex slices

2018-07-23 Thread Grégory Lielens
+1 on this. Seems easy a limited in scope, and it reduce the need to remember the details of slice constructor, just reuse the same syntax for getitem slices. Seems that the initial proposal was skipped just for timing reasons, and have a large support among numpy users. More mixed outside nump

Re: [Python-ideas] slice[] to get more complex slices

2018-07-22 Thread Serhiy Storchaka
22.07.18 22:03, Todd пише: For basic slices, the normal "slice(start, stop, step)" syntax works well.  But it becomes much more verbose to create more complicated slices that you want to re-use for multiple multidimensional data structures, like numpy, pandas, xarray, etc. One idea I had was

Re: [Python-ideas] slice[] to get more complex slices

2018-07-22 Thread Stefan Behnel
Todd schrieb am 22.07.2018 um 21:03: > For basic slices, the normal "slice(start, stop, step)" syntax works well. > But it becomes much more verbose to create more complicated slices that you > want to re-use for multiple multidimensional data structures, like numpy, > pandas, xarray, etc. > > One

[Python-ideas] slice[] to get more complex slices

2018-07-22 Thread Todd
For basic slices, the normal "slice(start, stop, step)" syntax works well. But it becomes much more verbose to create more complicated slices that you want to re-use for multiple multidimensional data structures, like numpy, pandas, xarray, etc. One idea I had was to allow creating slices by using