[issue33040] Make itertools.islice supports negative values for start and stop arguments for sized iterable object
Yaroslav Nikitenko added the comment: Sorry for a typo. The paragraph before the last should read Negative *step* fundamentally changes the algorithm:... flow[-1:None:-1]. -- ___ Python tracker <https://bugs.python.org/issue33040> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33040] Make itertools.islice supports negative values for start and stop arguments for sized iterable object
Yaroslav Nikitenko added the comment: I hope it's fine to add to closed topics here. I agree with the decision that islice should not handle a special case of sized containers vs iterables. However, I think that the support of negative indices in islice would be nice. A simple use case would be to get the last element of an iterable. I had to write my own code for that (you may read and/or use it if needed), because I needed this algorithm in my analysis. Here is the link to my function ISlice._run_negative_islice in my architectural framework for data analysis: https://github.com/ynikitenko/lena/blob/master/lena/flow/iterators.py#L150 or on https://lena.readthedocs.io/en/latest/flow.html#lena.flow.iterators.ISlice (I'm afraid the correct link might change later). I also agree that to support negative indices would require more work. Indeed, it seems that for each combination of positive/negative start/stop it required a new algorithm! I didn't implement negative steps. However, I think that because it's not easy to implement, it would be even better to include that in the standard library (because it would save other people from writing that). If we care about code reuse: I think that negative indices make the algorithm more useful, while non-trivial steps are redundant, because they can be implemented by a composition of a slice with step=1 with a simple slice with start, stop=None, None with step!=1. Negative slice fundamentally changes the algorithm: if one wants to have the flow inverted, fflow[0, None, -1], one would have to store it all in memory! Anyway it's easy to make this in a separate function. So I think it's more functional to implement negative indices and discard negative steps (or non-trivial steps at all). About drop_first, drop_last suggested above: I also think that they are redundant and would be better incorporated into islice. -- nosy: +ynikitenko ___ Python tracker <https://bugs.python.org/issue33040> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38801] Scientific notation doesn't work with itertools.islice
Yaroslav Nikitenko added the comment: Hello Raymond. Many thanks for your explanation. In this case I suggest any of the following: 1) distinguish between integer and floating numbers in scientific notation. Definitely, 1e+6 is an integer. I can't see where else numbers in scientific notation are defined as only floats. 2) to write explicitly in the documentation that scientific notation is always float. I searched documentation of 'scientific notation', but didn't found that (https://docs.python.org/3/search.html?q=scientific+notation_keywords=yes=default) 3) to provide a better exception message in islice if this is a known issue. Should I change parameters of my report or create a new one? I'm afraid this message may get lost if closed. -- ___ Python tracker <https://bugs.python.org/issue38801> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38801] Scientific notation doesn't work with itertools.islice
New submission from Yaroslav Nikitenko : Numbers written in scientific notation don't work with itertools.islice. Check this script: # a usual function works ## def works as well f = lambda x : x f(1e+6) # 100.0 import itertools # islice without scientific notation works itertools.islice([], 100) # itertools.islice([], 1e+6) # Traceback (most recent call last): # File "", line 1, in # ValueError: Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize. All this works well in Python 2.7.17, but scientific notation fails in Python 3.7.5. I use Fedora Core 29. -- components: Library (Lib) messages: 356618 nosy: ynikitenko priority: normal severity: normal status: open title: Scientific notation doesn't work with itertools.islice type: behavior versions: Python 3.7 ___ Python tracker <https://bugs.python.org/issue38801> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com