On Tue, Aug 25, 2020 at 10:58 AM David Mertz <me...@gnosis.cx> wrote:
> On Tue, Aug 25, 2020 at 2:26 AM Christopher Barker <python...@gmail.com> > wrote: > >> As for "why not" not being a motivator -- I agree, I posted it that easy >> because this conversation has brought up a number of examples where slice >> syntax is nice to use. And David Mertz pointed out, both numpy and pandas >> have a utility to make easier slices -- yes, that's an argument for why you >> don't need them, but it's also an argument for why there IS a need for >> slice objects outside of the square brackets, and if we need slice objects, >> then slice syntax is nice. >> > > Pandas is kinda special though. It semi-abuses Python syntax in quite a > few places. For example, here is an example from the Pandas docs: > > >>> idx = pd.IndexSlice>>> dfmi.loc[idx[:, 'B0':'B1'], :] > > There is a hierarchical index (MultiIndex) where we want to put slices as > some of the "dimensions" of slice items. It definitely makes sense in the > Pandas world, but I have never once encountered anywhere I would want > "stand-alone" slice objects outside of Pandas. I know NumPy includes the > same convenience, but it's not even coming to me immediately in what > context you would want that in NumPy. > I had to do it in a situation where I needed slices but couldn't tell ahead of time how many dimensions would be sliced. So I had to construct a dynamically-sized tuple of slices on-the-fly. I doubt this is not a common situation, though.
_______________________________________________ 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/EGEOV6YLGH7IWEWQDFLXPDF3UPQ3UEGS/ Code of Conduct: http://python.org/psf/codeofconduct/