@@ -894,7 +894,9 @@ class IndexCol(object):
894
894
pos : the position in the pytables
895
895
896
896
"""
897
- is_indexable = True
897
+ is_an_indexable = True
898
+ is_data_indexable = True
899
+ is_searchable = False
898
900
899
901
def __init__ (self , values = None , kind = None , typ = None , cname = None , itemsize = None , name = None , axis = None , kind_attr = None , pos = None , ** kwargs ):
900
902
self .values = values
@@ -1047,12 +1049,16 @@ class DataCol(IndexCol):
1047
1049
data : the actual data
1048
1050
cname : the column name in the table to hold the data (typeically values)
1049
1051
"""
1050
- is_indexable = False
1051
- is_searchable = False
1052
+ is_an_indexable = False
1053
+ is_data_indexable = False
1054
+ is_searchable = False
1052
1055
1053
1056
@classmethod
1054
1057
def create_for_block (cls , i = None , name = None , cname = None , ** kwargs ):
1055
1058
""" return a new datacol with the block i """
1059
+
1060
+ # a little hacky here, to avoid a backwards compability issue
1061
+ # columns in the table are named like: values_block_0...., but there name is values_0 (for kind attributes)
1056
1062
if cname is None :
1057
1063
cname = name or 'values_block_%d' % i
1058
1064
if name is None :
@@ -1110,18 +1116,18 @@ def set_atom(self, block, existing_col, min_itemsize, nan_rep, **kwargs):
1110
1116
elif inferred_type == 'date' :
1111
1117
raise NotImplementedError ("date is not implemented as a table column" )
1112
1118
1113
- self .set_atom_object (block , existing_col , min_itemsize , nan_rep )
1119
+ self .set_atom_string (block , existing_col , min_itemsize , nan_rep )
1114
1120
elif dtype == 'datetime64[ns]' :
1115
1121
raise NotImplementedError ("datetime64[ns] is not implemented as a table column" )
1116
1122
else :
1117
1123
self .set_atom_data (block )
1118
1124
1119
1125
return self
1120
1126
1121
- def get_atom_object (self , block , itemsize ):
1127
+ def get_atom_string (self , block , itemsize ):
1122
1128
return _tables ().StringCol (itemsize = itemsize , shape = block .shape [0 ])
1123
1129
1124
- def set_atom_object (self , block , existing_col , min_itemsize , nan_rep ):
1130
+ def set_atom_string (self , block , existing_col , min_itemsize , nan_rep ):
1125
1131
# fill nan items with myself
1126
1132
data = block .fillna (nan_rep ).values
1127
1133
@@ -1139,10 +1145,10 @@ def set_atom_object(self, block, existing_col, min_itemsize, nan_rep):
1139
1145
itemsize = eci
1140
1146
1141
1147
self .kind = 'string'
1142
- self .typ = self .get_atom_object (block , itemsize )
1143
- self .set_data (self .convert_object_data (data , itemsize ))
1148
+ self .typ = self .get_atom_string (block , itemsize )
1149
+ self .set_data (self .convert_string_data (data , itemsize ))
1144
1150
1145
- def convert_object_data (self , data , itemsize ):
1151
+ def convert_string_data (self , data , itemsize ):
1146
1152
return data .astype ('S%s' % itemsize )
1147
1153
1148
1154
def get_atom_data (self , block ):
@@ -1206,23 +1212,15 @@ def set_attr(self):
1206
1212
1207
1213
class DataIndexableCol (DataCol ):
1208
1214
""" represent a data column that can be indexed """
1215
+ is_data_indexable = True
1209
1216
1210
1217
@property
1211
1218
def is_searchable (self ):
1212
1219
return self .kind == 'string'
1213
1220
1214
- def get_atom_object (self , block , itemsize ):
1221
+ def get_atom_string (self , block , itemsize ):
1215
1222
return _tables ().StringCol (itemsize = itemsize )
1216
1223
1217
- # reshape the values if not shape (e.g. we are a scalar)
1218
- #if 'shape' not in kw:
1219
- # import pdb; pdb.set_trace()
1220
- # values = values.reshape(values.shape[1:])
1221
-
1222
-
1223
- def convert_object_data (self , data , itemsize ):
1224
- return data .astype ('S%s' % itemsize )
1225
-
1226
1224
def get_atom_data (self , block ):
1227
1225
return getattr (_tables (),"%sCol" % self .kind .capitalize ())()
1228
1226
@@ -1242,9 +1240,11 @@ class Table(object):
1242
1240
These are attributes that are store in the main table node, they are necessary
1243
1241
to recreate these tables when read back in.
1244
1242
1245
- index_axes: a list of tuples of the (original indexing axis and index column)
1243
+ index_axes : a list of tuples of the (original indexing axis and index column)
1246
1244
non_index_axes: a list of tuples of the (original index axis and columns on a non-indexing axis)
1247
- values_axes : a list of the columns which comprise the data of this table
1245
+ values_axes : a list of the columns which comprise the data of this table
1246
+ data_columns : a list of columns that we are allowing indexing (these become single columns in values_axes)
1247
+ nan_rep : the string to use for nan representations for string objects
1248
1248
1249
1249
"""
1250
1250
table_type = None
@@ -1429,7 +1429,7 @@ def create_index(self, columns = None, optlevel = None, kind = None):
1429
1429
1430
1430
# index all indexables and data_columns
1431
1431
if columns is None :
1432
- columns = [ a .cname for a in self .index_axes ] + [ v . cname for v in self . values_axes if v . name in set ( self . data_columns ) ]
1432
+ columns = [ a .cname for a in self .axes if a . is_data_indexable ]
1433
1433
if not isinstance (columns , (tuple ,list )):
1434
1434
columns = [ columns ]
1435
1435
@@ -1494,8 +1494,8 @@ def infer_axes(self):
1494
1494
self .non_index_axes = getattr (self .attrs ,'non_index_axes' ,None ) or []
1495
1495
self .data_columns = getattr (self .attrs ,'data_columns' ,None ) or []
1496
1496
self .nan_rep = getattr (self .attrs ,'nan_rep' ,None )
1497
- self .index_axes , self . values_axes = [ a . infer ( self . table ) for a in self . indexables if a . is_indexable ], [ a .infer (self .table ) for a in self .indexables if not a . is_indexable ]
1498
-
1497
+ self .index_axes = [ a .infer (self .table ) for a in self .indexables if a . is_an_indexable ]
1498
+ self . values_axes = [ a . infer ( self . table ) for a in self . indexables if not a . is_an_indexable ]
1499
1499
return True
1500
1500
1501
1501
def get_object (self , obj ):
@@ -2362,8 +2362,8 @@ def eval(self):
2362
2362
raise Exception ("passing a filterable condition to a non-table indexer [%s]" % str (self ))
2363
2363
2364
2364
def convert_value (self , v ):
2365
+ """ convert the expression that is in the term to something that is accepted by pytables """
2365
2366
2366
- #### a little hacky here, need to really figure out what we should convert ####x
2367
2367
if self .kind == 'datetime64' :
2368
2368
return [lib .Timestamp (v ).value , None ]
2369
2369
elif isinstance (v , datetime ) or hasattr (v ,'timetuple' ) or self .kind == 'date' :
0 commit comments