Skip to content

Commit 8829b25

Browse files
committed
BUG: fix pre-PyTables 2.3.1 issues
1 parent 7e59b5b commit 8829b25

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

pandas/io/pytables.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _tables():
8484

8585
# version requirements
8686
major, minor, subv = tables.__version__.split('.')
87-
if int(major) >= 2 and int(minor) >= 3:
87+
if int(major) >= 2 and int(minor[0]) >= 3:
8888
_table_supports_index = True
8989

9090
return _table_mod
@@ -400,7 +400,7 @@ def append(self, key, value, **kwargs):
400400
self._write_to_group(key, value, table=True, append=True, **kwargs)
401401

402402
def create_table_index(self, key, **kwargs):
403-
""" Create a pytables index on the table
403+
""" Create a pytables index on the table
404404
Paramaters
405405
----------
406406
key : object (the node to index)
@@ -569,7 +569,7 @@ def _read_block_manager(self, group):
569569
def _write_frame_table(self, group, df, append=False, comp=None, **kwargs):
570570
t = create_table(self, group, typ = 'appendable_frame')
571571
t.write(axes_to_index=[0], obj=df, append=append, compression=comp, **kwargs)
572-
572+
573573
def _write_wide(self, group, panel):
574574
panel._consolidate_inplace()
575575
self._write_block_manager(group, panel._data)
@@ -581,7 +581,7 @@ def _write_wide_table(self, group, panel, append=False, comp=None, **kwargs):
581581
t = create_table(self, group, typ = 'appendable_panel')
582582
t.write(axes_to_index=[1,2], obj=panel,
583583
append=append, compression=comp, **kwargs)
584-
584+
585585
def _read_wide_table(self, group, where=None):
586586
t = create_table(self, group)
587587
return t.read(where)
@@ -806,15 +806,15 @@ def _read_frame_table(self, group, where=None):
806806

807807

808808
class Col(object):
809-
""" a column description class
809+
""" a column description class
810810
811811
Parameters
812812
----------
813813
814814
values : the ndarray like converted values
815815
kind : a string description of this type
816816
typ : the pytables type
817-
817+
818818
"""
819819
is_indexable = True
820820

@@ -906,7 +906,7 @@ def validate_col(self):
906906

907907
# validate this column for string truncation (or reset to the max size)
908908
if self.kind == 'string':
909-
909+
910910
c = self.col
911911
if c is not None:
912912
if c.itemsize < self.itemsize:
@@ -1016,7 +1016,7 @@ class Table(object):
10161016
10171017
parent : my parent HDFStore
10181018
group : the group node where the table resides
1019-
1019+
10201020
"""
10211021
table_type = None
10221022
ndim = None
@@ -1047,7 +1047,7 @@ def nrows(self):
10471047
@property
10481048
def table(self):
10491049
""" return the table group """
1050-
return getattr(self.group, 'table', None)
1050+
return getattr(self.group, 'table', None)
10511051

10521052
@property
10531053
def handle(self):
@@ -1097,7 +1097,7 @@ def kinds_map(self):
10971097
def index_cols(self):
10981098
""" return a list of my index cols """
10991099
return [ i.cname for i in self.index_axes ]
1100-
1100+
11011101
def values_cols(self):
11021102
""" return a list of my values cols """
11031103
return [ i.cname for i in self.values_axes ]
@@ -1119,7 +1119,7 @@ def validate(self):
11191119
if ic is not None and ic != self.index_cols():
11201120
raise TypeError("incompatible index cols with existing [%s - %s]" %
11211121
(ic, self.index_cols()))
1122-
1122+
11231123
@property
11241124
def indexables(self):
11251125
""" create/cache the indexables if they don't exist """
@@ -1130,7 +1130,7 @@ def indexables(self):
11301130

11311131
# index columns
11321132
self._indexables.extend([ Col(name = i) for i in self.attrs.index_cols ])
1133-
1133+
11341134
# data columns
11351135
self._indexables.extend([ DataCol.create_for_block(i = i) for i, c in enumerate(self.attrs.values_cols) ])
11361136

@@ -1140,7 +1140,7 @@ def create_index(self, columns = None, optlevel = None, kind = None):
11401140
"""
11411141
Create a pytables index on the specified columns
11421142
note: cannot index Time64Col() currently; PyTables must be >= 2.3.1
1143-
1143+
11441144
11451145
Paramaters
11461146
----------
@@ -1309,7 +1309,7 @@ def read(self, where=None):
13091309

13101310
major = Factor.from_array(index)
13111311
minor = Factor.from_array(column)
1312-
1312+
13131313
J, K = len(major.levels), len(minor.levels)
13141314
key = major.labels * K + minor.labels
13151315

@@ -1373,7 +1373,7 @@ def read(self, where=None):
13731373

13741374
return wp
13751375

1376-
def write(self, axes_to_index, obj, append=False, compression=None,
1376+
def write(self, axes_to_index, obj, append=False, compression=None,
13771377
complevel=None, min_itemsize = None, **kwargs):
13781378

13791379
# create the table if it doesn't exist (or get it if it does)
@@ -1391,7 +1391,7 @@ def write(self, axes_to_index, obj, append=False, compression=None,
13911391

13921392
# set the table attributes
13931393
self.set_attrs()
1394-
1394+
13951395
# create the table
13961396
table = self.handle.createTable(self.group, **options)
13971397

@@ -1475,7 +1475,7 @@ def delete(self, where = None):
14751475
l.reverse()
14761476
for c in l:
14771477
table.removeRows(c)
1478-
1478+
14791479
self.handle.flush()
14801480

14811481
# return the number of rows removed
@@ -1725,7 +1725,7 @@ def _alias_to_class(alias):
17251725

17261726

17271727
class Term(object):
1728-
""" create a term object that holds a field, op, and value
1728+
""" create a term object that holds a field, op, and value
17291729
17301730
Parameters
17311731
----------
@@ -1748,7 +1748,7 @@ class Term(object):
17481748
Term('index', datetime(2012,11,14))
17491749
Term('major>20121114')
17501750
Term('minor', ['A','B'])
1751-
1751+
17521752
"""
17531753

17541754
_ops = ['<=','<','>=','>','!=','=']
@@ -1772,7 +1772,7 @@ def __init__(self, field, op = None, value = None, kinds = None):
17721772
op = f[1]
17731773
if len(f) > 2:
17741774
value = f[2]
1775-
1775+
17761776
# backwards compatible
17771777
if isinstance(field, dict):
17781778
self.field = field.get('field')
@@ -1808,7 +1808,7 @@ def __init__(self, field, op = None, value = None, kinds = None):
18081808

18091809
else:
18101810
raise Exception("Term does not understand the supplied field [%s]" % field)
1811-
1811+
18121812
# we have valid fields
18131813
if self.field is None or self.op is None or self.value is None:
18141814
raise Exception("Could not create this term [%s]" % str(self))
@@ -1848,19 +1848,19 @@ def kind(self):
18481848

18491849
def eval(self):
18501850
""" set the numexpr expression for this term """
1851-
1851+
18521852
# convert values
18531853
values = [ self.convert_value(v) for v in self.value ]
18541854

18551855
# equality conditions
18561856
if self.op in ['=','!=']:
1857-
1857+
18581858
if self.is_in_table:
18591859

18601860
# too many values to create the expression?
18611861
if len(values) <= 61:
18621862
self.condition = "(%s)" % ' | '.join([ "(%s == %s)" % (self.field,v[0]) for v in values])
1863-
1863+
18641864
# use a filter after reading
18651865
else:
18661866
self.filter = set([ v[1] for v in values ])
@@ -1874,7 +1874,7 @@ def eval(self):
18741874
if self.is_in_table:
18751875

18761876
self.condition = '(%s %s %s)' % (self.field, self.op, values[0][0])
1877-
1877+
18781878
def convert_value(self, v):
18791879

18801880
if self.field == 'index':

pandas/io/tests/test_pytables.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_append(self):
151151
store.append('df1', df[:10])
152152
store.append('df1', df[10:])
153153
tm.assert_frame_equal(store['df1'], df)
154-
154+
155155
store.put('df2', df[:10], table=True)
156156
store.append('df2', df[10:])
157157
tm.assert_frame_equal(store['df2'], df)
@@ -248,7 +248,7 @@ def _make_one_df():
248248
df['int1'] = 1
249249
df['int2'] = 2
250250
return df.consolidate()
251-
251+
252252
df1 = _make_one_df()
253253

254254
self.store.append('df1_mixed', df1)
@@ -361,7 +361,7 @@ def test_terms(self):
361361
]
362362
for t in terms:
363363
self.assertRaises(Exception, self.store.select, 'wp', t)
364-
364+
365365
self.assertRaises(Exception, Term.__init__)
366366
self.assertRaises(Exception, Term.__init__, 'blah')
367367
self.assertRaises(Exception, Term.__init__, 'index')
@@ -390,7 +390,7 @@ def test_terms(self):
390390

391391
for t in terms:
392392
self.store.select('wp', t)
393-
393+
394394
def test_series(self):
395395
s = tm.makeStringSeries()
396396
self._check_roundtrip(s, tm.assert_series_equal)
@@ -810,8 +810,8 @@ def _check_roundtrip_table(self, obj, comparator, compression=False):
810810
try:
811811
store.put('obj', obj, table=True)
812812
retrieved = store['obj']
813-
sorted_obj = _test_sort(obj)
814-
comparator(retrieved, sorted_obj)
813+
# sorted_obj = _test_sort(obj)
814+
comparator(retrieved, obj)
815815
finally:
816816
store.close()
817817
os.remove(self.scratchpath)

0 commit comments

Comments
 (0)