@@ -3832,6 +3832,7 @@ def create_axes(
3832
3832
else :
3833
3833
existing_table = None
3834
3834
3835
+ assert self .ndim == 2 # with next check, we must have len(axes) == 1
3835
3836
# currently support on ndim-1 axes
3836
3837
if len (axes ) != self .ndim - 1 :
3837
3838
raise ValueError (
@@ -3846,63 +3847,58 @@ def create_axes(
3846
3847
if nan_rep is None :
3847
3848
nan_rep = "nan"
3848
3849
3849
- # create axes to index and non_index
3850
- index_axes_map = dict ()
3851
- for i , a in enumerate (obj .axes ):
3850
+ # We construct the non-index-axis first, since that alters self.info
3851
+ idx = [x for x in [0 , 1 ] if x not in axes ][0 ]
3852
3852
3853
- if i in axes :
3854
- name = obj . _AXIS_NAMES [ i ]
3855
- new_index = _convert_index ( name , a , self . encoding , self . errors )
3856
- new_index . axis = i
3857
- index_axes_map [ i ] = new_index
3858
-
3859
- else :
3853
+ a = obj . axes [ idx ]
3854
+ # we might be able to change the axes on the appending data if necessary
3855
+ append_axis = list ( a )
3856
+ if existing_table is not None :
3857
+ indexer = len ( new_non_index_axes ) # i.e. 0
3858
+ exist_axis = existing_table . non_index_axes [ indexer ][ 1 ]
3859
+ if not array_equivalent ( np . array ( append_axis ), np . array ( exist_axis )) :
3860
3860
3861
- # we might be able to change the axes on the appending data if
3862
- # necessary
3863
- append_axis = list (a )
3864
- if existing_table is not None :
3865
- indexer = len (new_non_index_axes )
3866
- exist_axis = existing_table .non_index_axes [indexer ][1 ]
3867
- if not array_equivalent (
3868
- np .array (append_axis ), np .array (exist_axis )
3869
- ):
3870
-
3871
- # ahah! -> reindex
3872
- if array_equivalent (
3873
- np .array (sorted (append_axis )), np .array (sorted (exist_axis ))
3874
- ):
3875
- append_axis = exist_axis
3861
+ # ahah! -> reindex
3862
+ if array_equivalent (
3863
+ np .array (sorted (append_axis )), np .array (sorted (exist_axis ))
3864
+ ):
3865
+ append_axis = exist_axis
3876
3866
3877
- # the non_index_axes info
3878
- info = _get_info ( self .info , i )
3879
- info ["names" ] = list (a .names )
3880
- info ["type" ] = type (a ).__name__
3867
+ # the non_index_axes info
3868
+ info = self .info . setdefault ( idx , {} )
3869
+ info ["names" ] = list (a .names )
3870
+ info ["type" ] = type (a ).__name__
3881
3871
3882
- new_non_index_axes .append ((i , append_axis ))
3872
+ new_non_index_axes .append ((idx , append_axis ))
3883
3873
3884
- self .non_index_axes = new_non_index_axes
3874
+ # Now we can construct our new index axis
3875
+ idx = axes [0 ]
3876
+ a = obj .axes [idx ]
3877
+ name = obj ._AXIS_NAMES [idx ]
3878
+ new_index = _convert_index (name , a , self .encoding , self .errors )
3879
+ new_index .axis = idx
3885
3880
3886
- # set axis positions (based on the axes)
3887
- new_index_axes = [ index_axes_map [ a ] for a in axes ]
3888
- for j , iax in enumerate ( new_index_axes ):
3889
- iax . set_pos ( j )
3890
- iax . update_info ( self . info )
3881
+ # Because we are always 2D, there is only one new_index, so
3882
+ # we know it will have pos=0
3883
+ new_index . set_pos ( 0 )
3884
+ new_index . update_info ( self . info )
3885
+ new_index . maybe_set_size ( min_itemsize ) # check for column conflicts
3891
3886
3892
- j = len ( new_index_axes )
3887
+ self . non_index_axes = new_non_index_axes
3893
3888
3894
- # check for column conflicts
3895
- for a in new_index_axes :
3896
- a . maybe_set_size ( min_itemsize = min_itemsize )
3889
+ new_index_axes = [ new_index ]
3890
+ j = len ( new_index_axes ) # i.e. 1
3891
+ assert j == 1
3897
3892
3898
3893
# reindex by our non_index_axes & compute data_columns
3894
+ assert len (new_non_index_axes ) == 1
3899
3895
for a in new_non_index_axes :
3900
3896
obj = _reindex_axis (obj , a [0 ], a [1 ])
3901
3897
3902
3898
def get_blk_items (mgr , blocks ):
3903
3899
return [mgr .items .take (blk .mgr_locs ) for blk in blocks ]
3904
3900
3905
- transposed = new_index_axes [ 0 ] .axis == 1
3901
+ transposed = new_index .axis == 1
3906
3902
3907
3903
# figure out data_columns and get out blocks
3908
3904
block_obj = self .get_object (obj , transposed )._consolidate ()
0 commit comments