Hi Tony,
Il giorno 09/lug/2013, alle ore 06:38, Tony Yu <tsy...@gmail.com> 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 ------------------------------------------------------------------------------ See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today! http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk _______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users