@@ -961,8 +961,9 @@ def infer(self, table):
961
961
962
962
def convert (self , sel ):
963
963
""" set the values from this selection """
964
- self .values = _maybe_convert (sel .values [self .cname ], self .kind )
965
-
964
+ self .values = Index (_maybe_convert (sel .values [self .cname ], self .kind ))
965
+ self .factor = Categorical .from_array (self .values )
966
+
966
967
@property
967
968
def attrs (self ):
968
969
return self .table ._v_attrs
@@ -1481,6 +1482,22 @@ def create_axes(self, axes, obj, validate = True, min_itemsize = None):
1481
1482
if validate :
1482
1483
self .validate (existing_table )
1483
1484
1485
+ def process_axes (self , obj ):
1486
+ """ process axes filters """
1487
+
1488
+ def reindex (obj , axis , filt , ordered ):
1489
+ axis_name = obj ._get_axis_name (axis )
1490
+ ordd = ordered & filt
1491
+ ordd = sorted (ordered .get_indexer (ordd ))
1492
+ return obj .reindex_axis (ordered .take (ordd ), axis = obj ._get_axis_number (axis_name ), copy = False )
1493
+
1494
+ # apply the selection filters (but keep in the same order)
1495
+ if self .selection .filter :
1496
+ for axis , filt in self .selection .filter :
1497
+ obj = reindex (obj , axis , filt , getattr (obj ,obj ._get_axis_name (axis )))
1498
+
1499
+ return obj
1500
+
1484
1501
def create_description (self , compression = None , complevel = None ):
1485
1502
""" create the description of the table from the axes & values """
1486
1503
@@ -1556,8 +1573,7 @@ def read(self, where=None):
1556
1573
1557
1574
if not self .read_axes (where ): return None
1558
1575
1559
- indicies = [ i .values for i in self .index_axes ]
1560
- factors = [ Categorical .from_array (i ) for i in indicies ]
1576
+ factors = [ a .factor for a in self .index_axes ]
1561
1577
levels = [ f .levels for f in factors ]
1562
1578
N = [ len (f .levels ) for f in factors ]
1563
1579
labels = [ f .labels for f in factors ]
@@ -1597,7 +1613,8 @@ def read(self, where=None):
1597
1613
'appended' )
1598
1614
1599
1615
# reconstruct
1600
- long_index = MultiIndex .from_arrays (indicies )
1616
+ long_index = MultiIndex .from_arrays ([ i .values for i in self .index_axes ])
1617
+
1601
1618
1602
1619
for c in self .values_axes :
1603
1620
lp = DataFrame (c .data , index = long_index , columns = c .values )
@@ -1627,12 +1644,8 @@ def read(self, where=None):
1627
1644
for axis ,labels in self .non_index_axes :
1628
1645
wp = wp .reindex_axis (labels ,axis = axis ,copy = False )
1629
1646
1630
- # apply the selection filters (but keep in the same order)
1631
- if self .selection .filter :
1632
- filter_axis_name = wp ._get_axis_name (self .non_index_axes [0 ][0 ])
1633
- ordered = getattr (wp ,filter_axis_name )
1634
- new_axis = sorted (ordered & self .selection .filter )
1635
- wp = wp .reindex (** { filter_axis_name : new_axis , 'copy' : False })
1647
+ # apply the selection filters & axis orderings
1648
+ wp = self .process_axes (wp )
1636
1649
1637
1650
return wp
1638
1651
@@ -1792,7 +1805,7 @@ def read(self, where=None):
1792
1805
1793
1806
if not self .read_axes (where ): return None
1794
1807
1795
- index = Index ( self .index_axes [0 ].values )
1808
+ index = self .index_axes [0 ].values
1796
1809
frames = []
1797
1810
for a in self .values_axes :
1798
1811
columns = Index (a .values )
@@ -1815,16 +1828,8 @@ def read(self, where=None):
1815
1828
for axis ,labels in self .non_index_axes :
1816
1829
df = df .reindex_axis (labels ,axis = axis ,copy = False )
1817
1830
1818
- # apply the selection filters (but keep in the same order)
1819
- filter_axis_name = df ._get_axis_name (self .non_index_axes [0 ][0 ])
1820
-
1821
- ordered = getattr (df ,filter_axis_name )
1822
- if self .selection .filter :
1823
- ordd = ordered & self .selection .filter
1824
- ordd = sorted (ordered .get_indexer (ordd ))
1825
- df = df .reindex (** { filter_axis_name : ordered .take (ordd ), 'copy' : False })
1826
- else :
1827
- df = df .reindex (** { filter_axis_name : ordered , 'copy' : False })
1831
+ # apply the selection filters & axis orderings
1832
+ df = self .process_axes (df )
1828
1833
1829
1834
return df
1830
1835
@@ -2185,11 +2190,11 @@ def eval(self):
2185
2190
2186
2191
# use a filter after reading
2187
2192
else :
2188
- self .filter = set ( [ v [1 ] for v in values ])
2193
+ self .filter = ( self . field , Index ( [ v [1 ] for v in values ]) )
2189
2194
2190
2195
else :
2191
2196
2192
- self .filter = set ( [ v [1 ] for v in values ])
2197
+ self .filter = ( self . field , Index ( [ v [1 ] for v in values ]) )
2193
2198
2194
2199
else :
2195
2200
@@ -2244,10 +2249,10 @@ def __init__(self, table, where=None):
2244
2249
conds = [ t .condition for t in self .terms if t .condition is not None ]
2245
2250
if len (conds ):
2246
2251
self .condition = "(%s)" % ' & ' .join (conds )
2247
- self .filter = set ()
2252
+ self .filter = []
2248
2253
for t in self .terms :
2249
2254
if t .filter is not None :
2250
- self .filter |= t .filter
2255
+ self .filter . append ( t .filter )
2251
2256
2252
2257
def generate (self , where ):
2253
2258
""" where can be a : dict,list,tuple,string """
0 commit comments