Skip to content

Commit f3a183f

Browse files
committed
TST: HDFStore with compression test coverage
1 parent 8ad7f07 commit f3a183f

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

pandas/io/parsers.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,7 @@ def _convert_to_ndarrays(dct):
212212
values = np.array(values, dtype=float)
213213
except Exception:
214214
values = np.array(values, dtype=object)
215-
216-
try:
217-
values = _maybe_convert_int(values)
218-
except ValueError:
219-
pass
220-
221-
result[c] = values
222-
215+
result[c] = _maybe_convert_int(values)
223216
return result
224217

225218
def _try_parse_dates(values, parser=None):

pandas/io/pytables.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class HDFStore(object):
9898
>>> bar = store['foo'] # retrieve
9999
>>> store.close()
100100
"""
101-
def __init__(self, path, mode='a', complevel=0, complib=None,
101+
def __init__(self, path, mode='a', complevel=None, complib=None,
102102
fletcher32=False):
103103
try:
104104
import tables as _
@@ -162,7 +162,9 @@ def open(self, mode='a', warn=True):
162162
if self.handle is not None and self.handle.isopen:
163163
self.handle.close()
164164

165-
if self.complevel > 0 and self.complib is not None:
165+
if self.complib is not None:
166+
if self.complevel is None:
167+
self.complevel = 9
166168
self.filters = _tables().Filters(self.complevel,
167169
self.complib,
168170
fletcher32=self.fletcher32)
@@ -442,8 +444,8 @@ def _write_array(self, group, key, value):
442444
if atom is not None:
443445
# create an empty chunked array and fill it from value
444446
ca = self.handle.createCArray(group, key, atom,
445-
value.shape,
446-
filters=self.filters)
447+
value.shape,
448+
filters=self.filters)
447449
ca[:] = value
448450
return
449451

@@ -480,9 +482,10 @@ def _write_table(self, group, items=None, index=None, columns=None,
480482
complevel = self.complevel
481483
if complevel is None:
482484
complevel = 9
483-
options['filters'] = _tables().Filters(complevel=complevel,
484-
complib=compression,
485-
fletcher32=self.fletcher32)
485+
filters = _tables().Filters(complevel=complevel,
486+
complib=compression,
487+
fletcher32=self.fletcher32)
488+
options['filters'] = filters
486489
elif self.filters is not None:
487490
options['filters'] = self.filters
488491

pandas/io/tests/test_pytables.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ def test_frame(self):
169169
self._check_roundtrip(tdf, tm.assert_frame_equal,
170170
compression=True)
171171

172+
# not consolidated
173+
df['foo'] = np.random.randn(len(df))
174+
self.store['df'] = df
175+
recons = self.store['df']
176+
self.assert_(recons._data.is_consolidated())
177+
172178
def test_store_mixed(self):
173179
def _make_one():
174180
df = tm.makeDataFrame()
@@ -200,6 +206,16 @@ def _make_one():
200206
self._check_roundtrip(df1['bool1'], tm.assert_series_equal)
201207
self._check_roundtrip(df1['int1'], tm.assert_series_equal)
202208

209+
# try with compression
210+
self._check_roundtrip(df1['obj1'], tm.assert_series_equal,
211+
compression=True)
212+
self._check_roundtrip(df1['bool1'], tm.assert_series_equal,
213+
compression=True)
214+
self._check_roundtrip(df1['int1'], tm.assert_series_equal,
215+
compression=True)
216+
self._check_roundtrip(df1, tm.assert_frame_equal,
217+
compression=True)
218+
203219
def test_wide(self):
204220
wp = tm.makeWidePanel()
205221
self._check_roundtrip(wp, tm.assert_panel_equal)
@@ -293,7 +309,6 @@ def test_select_filter_corner(self):
293309
def _check_roundtrip(self, obj, comparator, compression=False):
294310
options = {}
295311
if compression:
296-
options['complevel'] = 9
297312
options['complib'] = 'blosc'
298313

299314
store = HDFStore(self.scratchpath, 'w', **options)
@@ -308,7 +323,6 @@ def _check_roundtrip(self, obj, comparator, compression=False):
308323
def _check_roundtrip_table(self, obj, comparator, compression=False):
309324
options = {}
310325
if compression:
311-
options['complevel'] = 9
312326
options['complib'] = 'blosc'
313327

314328
store = HDFStore(self.scratchpath, 'w', **options)

0 commit comments

Comments
 (0)