@@ -667,7 +667,7 @@ def func(_start, _stop):
667
667
axis = list (set ([t .non_index_axes [0 ][0 ] for t in tbls ]))[0 ]
668
668
669
669
# concat and return
670
- return concat (objs , axis = axis , verify_integrity = True )
670
+ return concat (objs , axis = axis , verify_integrity = True ). consolidate ()
671
671
672
672
if iterator or chunksize is not None :
673
673
return TableIterator (self , func , nrows = nrows , start = start , stop = stop , chunksize = chunksize , auto_close = auto_close )
@@ -2910,9 +2910,7 @@ def create_axes(self, axes, obj, validate=True, nan_rep=None, data_columns=None,
2910
2910
2911
2911
# reindex by our non_index_axes & compute data_columns
2912
2912
for a in self .non_index_axes :
2913
- labels = _ensure_index (a [1 ])
2914
- if not labels .equals (obj ._get_axis (a [0 ])):
2915
- obj = obj .reindex_axis (labels , axis = a [0 ])
2913
+ obj = _reindex_axis (obj , a [0 ], a [1 ])
2916
2914
2917
2915
# figure out data_columns and get out blocks
2918
2916
block_obj = self .get_object (obj ).consolidate ()
@@ -3000,11 +2998,7 @@ def process_axes(self, obj, columns=None):
3000
2998
3001
2999
# reorder by any non_index_axes & limit to the select columns
3002
3000
for axis , labels in self .non_index_axes :
3003
- if columns is not None :
3004
- labels = Index (labels ) & Index (columns )
3005
- labels = _ensure_index (labels )
3006
- if not labels .equals (obj ._get_axis (axis )):
3007
- obj = obj .reindex_axis (labels , axis = axis )
3001
+ obj = _reindex_axis (obj , axis , labels , columns )
3008
3002
3009
3003
# apply the selection filters (but keep in the same order)
3010
3004
if self .selection .filter :
@@ -3219,7 +3213,7 @@ def read(self, where=None, columns=None, **kwargs):
3219
3213
if len (objs ) == 1 :
3220
3214
wp = objs [0 ]
3221
3215
else :
3222
- wp = concat (objs , axis = 0 , verify_integrity = False )
3216
+ wp = concat (objs , axis = 0 , verify_integrity = False ). consolidate ()
3223
3217
3224
3218
# apply the selection filters & axis orderings
3225
3219
wp = self .process_axes (wp , columns = columns )
@@ -3510,7 +3504,7 @@ def read(self, where=None, columns=None, **kwargs):
3510
3504
if len (frames ) == 1 :
3511
3505
df = frames [0 ]
3512
3506
else :
3513
- df = concat (frames , axis = 1 , verify_integrity = False )
3507
+ df = concat (frames , axis = 1 , verify_integrity = False ). consolidate ()
3514
3508
3515
3509
# apply the selection filters & axis orderings
3516
3510
df = self .process_axes (df , columns = columns )
@@ -3683,6 +3677,26 @@ class AppendableNDimTable(AppendablePanelTable):
3683
3677
obj_type = Panel4D
3684
3678
3685
3679
3680
+ def _reindex_axis (obj , axis , labels , other = None ):
3681
+ ax = obj ._get_axis (axis )
3682
+ labels = _ensure_index (labels )
3683
+
3684
+ # try not to reindex even if other is provided
3685
+ # if it equals our current index
3686
+ if other is not None :
3687
+ other = _ensure_index (other )
3688
+ if (other is None or labels .equals (other )) and labels .equals (ax ):
3689
+ return obj
3690
+
3691
+ labels = _ensure_index (labels .unique ())
3692
+ if other is not None :
3693
+ labels = labels & _ensure_index (other .unique ())
3694
+ if not labels .equals (ax ):
3695
+ slicer = [ slice (None , None ) ] * obj .ndim
3696
+ slicer [axis ] = labels
3697
+ obj = obj .loc [tuple (slicer )]
3698
+ return obj
3699
+
3686
3700
def _get_info (info , name ):
3687
3701
""" get/create the info for this name """
3688
3702
try :
0 commit comments