Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #123 when sliding_window n was larger than the sequence #129

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cytoolz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from .compatibility import map, filter

# from . import sandbox

from functools import partial, reduce

sorted = sorted
Expand All @@ -21,6 +19,8 @@
flip = functoolz.flip = curry(functoolz.flip)
memoize = functoolz.memoize = curry(functoolz.memoize)

from . import curried # sandbox

functoolz._sigs.update_signature_registry()

from ._version import __version__, __toolz_version__
10 changes: 5 additions & 5 deletions cytoolz/itertoolz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,7 @@ cdef class sliding_window:
cdef Py_ssize_t i
self.iterseq = iter(seq)
self.prev = PyTuple_New(n)
for i in range(1, n):
seq = next(self.iterseq)
for i, seq in enumerate(islice(self.iterseq, n-1), 1):
Py_INCREF(seq)
PyTuple_SET_ITEM(self.prev, i, seq)
self.n = n
Expand All @@ -977,14 +976,15 @@ cdef class sliding_window:
cdef tuple current
cdef object item
cdef Py_ssize_t i

item = next(self.iterseq)
current = PyTuple_New(self.n)
Py_INCREF(item)
PyTuple_SET_ITEM(current, self.n-1, item)
for i in range(1, self.n):
item = self.prev[i]
Py_INCREF(item)
PyTuple_SET_ITEM(current, i-1, item)
item = next(self.iterseq)
Py_INCREF(item)
PyTuple_SET_ITEM(current, self.n-1, item)
self.prev = current
return current

Expand Down
1 change: 0 additions & 1 deletion cytoolz/tests/test_inspect_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ def add_blacklist(mod, attr):
blacklist.add(getattr(mod, attr))

add_blacklist(builtins, 'basestring')
add_blacklist(builtins, 'breakpoint')
add_blacklist(builtins, 'NoneType')
add_blacklist(builtins, '__metaclass__')
add_blacklist(builtins, 'sequenceiterator')
Expand Down
1 change: 1 addition & 0 deletions cytoolz/tests/test_itertoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def test_sliding_window():

def test_sliding_window_of_short_iterator():
assert list(sliding_window(3, [1, 2])) == []
assert list(sliding_window(7, [1, 2])) == []


def test_partition():
Expand Down