Skip to content

Commit b7a082a

Browse files
committed
CLN: do not piggyback idx size on table obj
1 parent e9c7c39 commit b7a082a

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

pandas/io/pytables.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,11 +1456,6 @@ def __init__(self, store, s, func, where, nrows, start=None, stop=None,
14561456
stop = nrows
14571457
stop = min(nrows, stop)
14581458

1459-
# Piggy-back normalized `nrows` (considering start and stop) onto
1460-
# PyTables tables object so that the GenericIndexCol constructor
1461-
# knows how large the index should be.
1462-
self.s.table._nrows_to_read = stop - start
1463-
14641459
self.nrows = nrows
14651460
self.start = start
14661461
self.stop = stop
@@ -1629,7 +1624,7 @@ def infer(self, handler):
16291624
new_self.read_metadata(handler)
16301625
return new_self
16311626

1632-
def convert(self, values, nan_rep, encoding, errors):
1627+
def convert(self, values, nan_rep, encoding, errors, **kwargs):
16331628
""" set the values from this selection: take = take ownership """
16341629

16351630
# values is a recarray
@@ -1818,18 +1813,13 @@ class GenericIndexCol(IndexCol):
18181813
def is_indexed(self):
18191814
return False
18201815

1821-
def convert(self, values, nan_rep, encoding, errors):
1816+
def convert(self, values, nan_rep, encoding, errors, **kwargs):
18221817
""" set the values from this selection: take = take ownership """
18231818

1824-
if hasattr(self.table, '_nrows_to_read'):
1825-
# The `_nrows_to_read` property is set on the table object by the
1826-
# code path invoked by the top-level `read_hdf()`, and calculated
1827-
# based on the start` and `stop` integer values. These values allow
1828-
# for a sub-selection and likewise the index size needs to be
1829-
# adjusted to the size of this sub-selection.
1830-
self.values = Int64Index(np.arange(self.table._nrows_to_read))
1831-
else:
1832-
self.values = Int64Index(np.arange(self.table.nrows))
1819+
start = kwargs.get('start', 0)
1820+
stop = kwargs.get('stop', self.table.nrows)
1821+
stop = min(stop, self.table.nrows)
1822+
self.values = Int64Index(np.arange(stop - start))
18331823

18341824
return self
18351825

@@ -2173,7 +2163,7 @@ def validate_attr(self, append):
21732163
raise ValueError("appended items dtype do not match existing "
21742164
"items dtype in table!")
21752165

2176-
def convert(self, values, nan_rep, encoding, errors):
2166+
def convert(self, values, nan_rep, encoding, errors, **kwargs):
21772167
"""set the data from this selection (and convert to the correct dtype
21782168
if we can)
21792169
"""
@@ -3445,8 +3435,10 @@ def read_axes(self, where, **kwargs):
34453435
# convert the data
34463436
for a in self.axes:
34473437
a.set_info(self.info)
3438+
# `kwargs` may contain `start` and `stop` arguments if passed to
3439+
# `store.select()`. If set they determine the index size.
34483440
a.convert(values, nan_rep=self.nan_rep, encoding=self.encoding,
3449-
errors=self.errors)
3441+
errors=self.errors, **kwargs)
34503442

34513443
return True
34523444

0 commit comments

Comments
 (0)