@@ -3734,7 +3734,7 @@ def read_axes(
3734
3734
3735
3735
return True
3736
3736
3737
- def get_object (self , obj ):
3737
+ def get_object (self , obj , transposed : bool ):
3738
3738
""" return the data for this obj """
3739
3739
return obj
3740
3740
@@ -3838,15 +3838,13 @@ def create_axes(
3838
3838
)
3839
3839
3840
3840
# create according to the new data
3841
- self . non_index_axes = []
3842
- self . data_columns = []
3841
+ new_non_index_axes : List = []
3842
+ new_data_columns : List [ Optional [ str ]] = []
3843
3843
3844
3844
# nan_representation
3845
3845
if nan_rep is None :
3846
3846
nan_rep = "nan"
3847
3847
3848
- self .nan_rep = nan_rep
3849
-
3850
3848
# create axes to index and non_index
3851
3849
index_axes_map = dict ()
3852
3850
for i , a in enumerate (obj .axes ):
@@ -3863,7 +3861,7 @@ def create_axes(
3863
3861
# necessary
3864
3862
append_axis = list (a )
3865
3863
if existing_table is not None :
3866
- indexer = len (self . non_index_axes )
3864
+ indexer = len (new_non_index_axes )
3867
3865
exist_axis = existing_table .non_index_axes [indexer ][1 ]
3868
3866
if not array_equivalent (
3869
3867
np .array (append_axis ), np .array (exist_axis )
@@ -3880,34 +3878,37 @@ def create_axes(
3880
3878
info ["names" ] = list (a .names )
3881
3879
info ["type" ] = type (a ).__name__
3882
3880
3883
- self .non_index_axes .append ((i , append_axis ))
3881
+ new_non_index_axes .append ((i , append_axis ))
3882
+
3883
+ self .non_index_axes = new_non_index_axes
3884
3884
3885
3885
# set axis positions (based on the axes)
3886
3886
new_index_axes = [index_axes_map [a ] for a in axes ]
3887
3887
for j , iax in enumerate (new_index_axes ):
3888
3888
iax .set_pos (j )
3889
3889
iax .update_info (self .info )
3890
- self .index_axes = new_index_axes
3891
3890
3892
- j = len (self . index_axes )
3891
+ j = len (new_index_axes )
3893
3892
3894
3893
# check for column conflicts
3895
- for a in self . axes :
3894
+ for a in new_index_axes :
3896
3895
a .maybe_set_size (min_itemsize = min_itemsize )
3897
3896
3898
3897
# reindex by our non_index_axes & compute data_columns
3899
- for a in self . non_index_axes :
3898
+ for a in new_non_index_axes :
3900
3899
obj = _reindex_axis (obj , a [0 ], a [1 ])
3901
3900
3902
3901
def get_blk_items (mgr , blocks ):
3903
3902
return [mgr .items .take (blk .mgr_locs ) for blk in blocks ]
3904
3903
3904
+ transposed = new_index_axes [0 ].axis == 1
3905
+
3905
3906
# figure out data_columns and get out blocks
3906
- block_obj = self .get_object (obj )._consolidate ()
3907
+ block_obj = self .get_object (obj , transposed )._consolidate ()
3907
3908
blocks = block_obj ._data .blocks
3908
3909
blk_items = get_blk_items (block_obj ._data , blocks )
3909
- if len (self . non_index_axes ):
3910
- axis , axis_labels = self . non_index_axes [0 ]
3910
+ if len (new_non_index_axes ):
3911
+ axis , axis_labels = new_non_index_axes [0 ]
3911
3912
data_columns = self .validate_data_columns (data_columns , min_itemsize )
3912
3913
if len (data_columns ):
3913
3914
mgr = block_obj .reindex (
@@ -3945,7 +3946,7 @@ def get_blk_items(mgr, blocks):
3945
3946
blk_items = new_blk_items
3946
3947
3947
3948
# add my values
3948
- self . values_axes = []
3949
+ vaxes = []
3949
3950
for i , (b , b_items ) in enumerate (zip (blocks , blk_items )):
3950
3951
3951
3952
# shape of the data column are the indexable axes
@@ -3959,7 +3960,7 @@ def get_blk_items(mgr, blocks):
3959
3960
if not (name is None or isinstance (name , str )):
3960
3961
# TODO: should the message here be more specifically non-str?
3961
3962
raise ValueError ("cannot have non-object label DataIndexableCol" )
3962
- self . data_columns .append (name )
3963
+ new_data_columns .append (name )
3963
3964
3964
3965
# make sure that we match up the existing columns
3965
3966
# if we have an existing table
@@ -3987,10 +3988,15 @@ def get_blk_items(mgr, blocks):
3987
3988
)
3988
3989
col .set_pos (j )
3989
3990
3990
- self . values_axes .append (col )
3991
+ vaxes .append (col )
3991
3992
3992
3993
j += 1
3993
3994
3995
+ self .nan_rep = nan_rep
3996
+ self .data_columns = new_data_columns
3997
+ self .values_axes = vaxes
3998
+ self .index_axes = new_index_axes
3999
+
3994
4000
# validate our min_itemsize
3995
4001
self .validate_min_itemsize (min_itemsize )
3996
4002
@@ -4428,9 +4434,9 @@ class AppendableFrameTable(AppendableTable):
4428
4434
def is_transposed (self ) -> bool :
4429
4435
return self .index_axes [0 ].axis == 1
4430
4436
4431
- def get_object (self , obj ):
4437
+ def get_object (self , obj , transposed : bool ):
4432
4438
""" these are written transposed """
4433
- if self . is_transposed :
4439
+ if transposed :
4434
4440
obj = obj .T
4435
4441
return obj
4436
4442
@@ -4512,7 +4518,7 @@ class AppendableSeriesTable(AppendableFrameTable):
4512
4518
def is_transposed (self ) -> bool :
4513
4519
return False
4514
4520
4515
- def get_object (self , obj ):
4521
+ def get_object (self , obj , transposed : bool ):
4516
4522
return obj
4517
4523
4518
4524
def write (self , obj , data_columns = None , ** kwargs ):
0 commit comments