From: Antonio V. <ant...@ti...> - 2013-07-09 05:59:20
|
Hi Tony, Il giorno 09/lug/2013, alle ore 06:38, Tony Yu <ts...@gm...> ha scritto: > Hi, > > I ran into a subtle, unexpected issue while using `itertools.islice`. I wanted to pass slices of an array for processing without actually reading the entire array, and I wanted that processing function to know nothing about how I'm taking that slice. To that end, I had a loop that sliced the array using `itertools.islice` and called the function on each slice. Instead of returning the slice I specified, `islice` treated the previous end slice as the starting point to the next slice. > > That description is a bit confusing, but the example below (along with the attached test data) should illustrate the point. Maybe I'm missing something, but the only work around that I found was to set a private flag (e.g. `h5.root.array._init = False`) on each call to `islice` to reset the counter used in `__iter__`. > > I'm not sure if this is expected behavior or not, but it does differ from how `islice` works on numpy arrays (as demonstrated in the example below). I used the google and nothing similar came up, so I thought I'd post here. > > Best, > -Tony > > > #~~~~ > > import tables > import itertools > import numpy as np > > > h5 = tables.openFile('test.h5') > array = np.arange(100) > for i in range(5): > # Numpy array slice always returns 0..10 > print list(itertools.islice(array, 0, 10)) > # PyTables array slice shifts with each iteration > print list(itertools.islice(h5.root.array, 0, 10)) > h5.close() > <test.h5>------------------------------------------------------------------------------ Yes, this is a bug IMO. Thank you for reporting and thank you for the small demonstration script. Can you please file a bug report on github [1]? Please also add info about the PyTables version you used for the test.. [1] https://github.com/PyTables/PyTables/issues -- Antonio Valentino |