Skip to content

Commit 074b485

Browse files
amolkahatjreback
authored andcommitted
Fixed Value Error when doing HDFStore.Select of contiguous mixed-data (pandas-dev#17670)
1 parent 45bd471 commit 074b485

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ I/O
603603
- Bug in :func:`read_html` where import check fails when run in multiple threads (:issue:`16928`)
604604
- Bug in :func:`read_csv` where automatic delimiter detection caused a ``TypeError`` to be thrown when a bad line was encountered rather than the correct error message (:issue:`13374`)
605605
- Bug in ``DataFrame.to_html()`` with ``notebook=True`` where DataFrames with named indices or non-MultiIndex indices had undesired horizontal or vertical alignment for column or row labels, respectively (:issue:`16792`)
606+
- Bug in :func:`HDFStore.select` when reading a contiguous mixed-data table featuring VLArray (:issue:`17021`)
606607

607608
Plotting
608609
^^^^^^^^

pandas/io/pytables.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2441,13 +2441,12 @@ def read_array(self, key, start=None, stop=None):
24412441
""" read an array for the specified node (off of group """
24422442
import tables
24432443
node = getattr(self.group, key)
2444-
data = node[start:stop]
24452444
attrs = node._v_attrs
24462445

24472446
transposed = getattr(attrs, 'transposed', False)
24482447

24492448
if isinstance(node, tables.VLArray):
2450-
ret = data[0]
2449+
ret = node[0][start:stop]
24512450
else:
24522451
dtype = getattr(attrs, 'value_type', None)
24532452
shape = getattr(attrs, 'shape', None)
@@ -2456,7 +2455,7 @@ def read_array(self, key, start=None, stop=None):
24562455
# length 0 axis
24572456
ret = np.empty(shape, dtype=dtype)
24582457
else:
2459-
ret = data
2458+
ret = node[start:stop]
24602459

24612460
if dtype == u('datetime64'):
24622461

pandas/tests/io/test_pytables.py

+13
Original file line numberDiff line numberDiff line change
@@ -4391,6 +4391,19 @@ def test_path_pathlib(self):
43914391
lambda p: pd.read_hdf(p, 'df'))
43924392
tm.assert_frame_equal(df, result)
43934393

4394+
@pytest.mark.parametrize('start, stop', [(0, 2), (1, 2), (None, None)])
4395+
def test_contiguous_mixed_data_table(self, start, stop):
4396+
# GH 17021
4397+
# ValueError when reading a contiguous mixed-data table ft. VLArray
4398+
df = DataFrame({'a': Series([20111010, 20111011, 20111012]),
4399+
'b': Series(['ab', 'cd', 'ab'])})
4400+
4401+
with ensure_clean_store(self.path) as store:
4402+
store.append('test_dataset', df)
4403+
4404+
result = store.select('test_dataset', start=start, stop=stop)
4405+
assert_frame_equal(df[start:stop], result)
4406+
43944407
def test_path_pathlib_hdfstore(self):
43954408
df = tm.makeDataFrame()
43964409

0 commit comments

Comments
 (0)