@@ -724,8 +724,9 @@ def select_as_multiple(self, keys, where=None, selector=None, columns=None,
724724
725725 Exceptions
726726 ----------
727- raise if any of the keys don't refer to tables or if they are not ALL
728- THE SAME DIMENSIONS
727+ raises KeyError if keys or selector is not found or keys is empty
728+ raises TypeError if keys is not a list or tuple
729+ raises ValueError if the tables are not ALL THE SAME DIMENSIONS
729730 """
730731
731732 # default to single select
@@ -748,12 +749,13 @@ def select_as_multiple(self, keys, where=None, selector=None, columns=None,
748749
749750 # collect the tables
750751 tbls = [self .get_storer (k ) for k in keys ]
752+ s = self .get_storer (selector )
751753
752754 # validate rows
753755 nrows = None
754- for t , k in zip (tbls , keys ):
756+ for t , k in itertools . chain ([( s , selector )], zip (tbls , keys ) ):
755757 if t is None :
756- raise TypeError ("Invalid table [%s]" % k )
758+ raise KeyError ("Invalid table [%s]" % k )
757759 if not t .is_table :
758760 raise TypeError (
759761 "object [%s] is not a table, and cannot be used in all "
@@ -766,22 +768,17 @@ def select_as_multiple(self, keys, where=None, selector=None, columns=None,
766768 raise ValueError (
767769 "all tables must have exactly the same nrows!" )
768770
769- # select coordinates from the selector table
770- try :
771- c = self .select_as_coordinates (
772- selector , where , start = start , stop = stop )
773- nrows = len (c )
774- except Exception :
775- raise ValueError ("invalid selector [%s]" % selector )
771+ # axis is the concentation axes
772+ axis = list (set ([t .non_index_axes [0 ][0 ] for t in tbls ]))[0 ]
776773
777774 def func (_start , _stop ):
778-
779- # collect the returns objs
780- objs = [ t . read ( where = c [ _start : _stop ], columns = columns )
781- for t in tbls ]
782-
783- # axis is the concentation axes
784- axis = list ( set ([ t . non_index_axes [ 0 ][ 0 ] for t in tbls ]))[ 0 ]
775+ if where is not None :
776+ c = s . read_coordinates ( where = where , start = _start , stop = _stop , ** kwargs )
777+ else :
778+ c = None
779+
780+ objs = [ t . read ( where = c , start = _start , stop = _stop ,
781+ columns = columns , ** kwargs ) for t in tbls ]
785782
786783 # concat and return
787784 return concat (objs , axis = axis ,
@@ -860,7 +857,7 @@ def remove(self, key, where=None, start=None, stop=None):
860857 raise KeyError ('No object named %s in the file' % key )
861858
862859 # remove the node
863- if where is None :
860+ if where is None and start is None and stop is None :
864861 s .group ._f_remove (recursive = True )
865862
866863 # delete from the table
@@ -2139,11 +2136,9 @@ def write(self, **kwargs):
21392136 raise NotImplementedError (
21402137 "cannot write on an abstract storer: sublcasses should implement" )
21412138
2142- def delete (self , where = None , ** kwargs ):
2143- """support fully deleting the node in its entirety (only) - where
2144- specification must be None
2145- """
2146- if where is None :
2139+ def delete (self , where = None , start = None , stop = None , ** kwargs ):
2140+ """ support fully deleting the node in its entirety (only) - where specification must be None """
2141+ if where is None and start is None and stop is None :
21472142 self ._handle .removeNode (self .group , recursive = True )
21482143 return None
21492144
@@ -3381,9 +3376,15 @@ def read_coordinates(self, where=None, start=None, stop=None, **kwargs):
33813376 # create the selection
33823377 self .selection = Selection (
33833378 self , where = where , start = start , stop = stop , ** kwargs )
3384- return Index (self .selection .select_coords ())
3379+ coords = self .selection .select_coords ()
3380+ if self .selection .filter is not None :
3381+ for field , op , filt in self .selection .filter .format ():
3382+ data = self .read_column (field , start = coords .min (), stop = coords .max ()+ 1 )
3383+ coords = coords [op (data .iloc [coords - coords .min ()], filt ).values ]
33853384
3386- def read_column (self , column , where = None , ** kwargs ):
3385+ return Index (coords )
3386+
3387+ def read_column (self , column , where = None , start = None , stop = None , ** kwargs ):
33873388 """return a single column from the table, generally only indexables
33883389 are interesting
33893390 """
@@ -3411,7 +3412,7 @@ def read_column(self, column, where=None, **kwargs):
34113412 # column must be an indexable or a data column
34123413 c = getattr (self .table .cols , column )
34133414 a .set_info (self .info )
3414- return Series (a .convert (c [: ], nan_rep = self .nan_rep ,
3415+ return Series (a .convert (c [start : stop ], nan_rep = self .nan_rep ,
34153416 encoding = self .encoding ).take_data ())
34163417
34173418 raise KeyError ("column [%s] not found in the table" % column )
@@ -3712,12 +3713,19 @@ def write_data_chunk(self, indexes, mask, values):
37123713 except Exception as detail :
37133714 raise TypeError ("tables cannot write this data -> %s" % detail )
37143715
3715- def delete (self , where = None , ** kwargs ):
3716+ def delete (self , where = None , start = None , stop = None , ** kwargs ):
37163717
37173718 # delete all rows (and return the nrows)
37183719 if where is None or not len (where ):
3719- nrows = self .nrows
3720- self ._handle .removeNode (self .group , recursive = True )
3720+ if start is None and stop is None :
3721+ nrows = self .nrows
3722+ self ._handle .removeNode (self .group , recursive = True )
3723+ else :
3724+ # pytables<3.0 would remove a single row with stop=None
3725+ if stop is None :
3726+ stop = self .nrows
3727+ nrows = self .table .removeRows (start = start , stop = stop )
3728+ self .table .flush ()
37213729 return nrows
37223730
37233731 # infer the data kind
@@ -3726,7 +3734,7 @@ def delete(self, where=None, **kwargs):
37263734
37273735 # create the selection
37283736 table = self .table
3729- self .selection = Selection (self , where , ** kwargs )
3737+ self .selection = Selection (self , where , start = start , stop = stop , ** kwargs )
37303738 values = self .selection .select_coords ()
37313739
37323740 # delete the rows in reverse order
@@ -4303,13 +4311,25 @@ def select_coords(self):
43034311 """
43044312 generate the selection
43054313 """
4306- if self .condition is None :
4307- return np .arange (self .table .nrows )
4314+ start , stop = self .start , self .stop
4315+ nrows = self .table .nrows
4316+ if start is None :
4317+ start = 0
4318+ elif start < 0 :
4319+ start += nrows
4320+ if self .stop is None :
4321+ stop = nrows
4322+ elif stop < 0 :
4323+ stop += nrows
43084324
4309- return self .table .table .getWhereList (self .condition .format (),
4310- start = self .start , stop = self .stop ,
4311- sort = True )
4325+ if self .condition is not None :
4326+ return self .table .table .getWhereList (self .condition .format (),
4327+ start = start , stop = stop ,
4328+ sort = True )
4329+ elif self .coordinates is not None :
4330+ return self .coordinates
43124331
4332+ return np .arange (start , stop )
43134333
43144334# utilities ###
43154335
0 commit comments