80
80
if TYPE_CHECKING :
81
81
from tables import Col , File , Node
82
82
83
+ from pandas .core .internals import Block
84
+
83
85
84
86
# versioning attribute
85
87
_version = "0.15.2"
@@ -3860,20 +3862,17 @@ def _create_axes(
3860
3862
for a in new_non_index_axes :
3861
3863
obj = _reindex_axis (obj , a [0 ], a [1 ])
3862
3864
3863
- def get_blk_items (mgr , blocks ):
3864
- return [mgr .items .take (blk .mgr_locs ) for blk in blocks ]
3865
-
3866
3865
transposed = new_index .axis == 1
3867
3866
3868
3867
# figure out data_columns and get out blocks
3869
3868
data_columns = self .validate_data_columns (
3870
3869
data_columns , min_itemsize , new_non_index_axes
3871
3870
)
3872
3871
3873
- block_obj = self .get_object (obj , transposed )._consolidate ()
3872
+ frame = self .get_object (obj , transposed )._consolidate ()
3874
3873
3875
3874
blocks , blk_items = self ._get_blocks_and_items (
3876
- block_obj , table_exists , new_non_index_axes , self .values_axes , data_columns
3875
+ frame , table_exists , new_non_index_axes , self .values_axes , data_columns
3877
3876
)
3878
3877
3879
3878
# add my values
@@ -3978,35 +3977,39 @@ def get_blk_items(mgr, blocks):
3978
3977
3979
3978
@staticmethod
3980
3979
def _get_blocks_and_items (
3981
- block_obj , table_exists , new_non_index_axes , values_axes , data_columns
3980
+ frame : DataFrame ,
3981
+ table_exists : bool ,
3982
+ new_non_index_axes ,
3983
+ values_axes ,
3984
+ data_columns ,
3982
3985
):
3983
3986
# Helper to clarify non-state-altering parts of _create_axes
3984
3987
3985
- def get_blk_items (mgr , blocks ):
3986
- return [mgr .items .take (blk .mgr_locs ) for blk in blocks ]
3988
+ def get_blk_items (mgr ):
3989
+ return [mgr .items .take (blk .mgr_locs ) for blk in mgr . blocks ]
3987
3990
3988
- blocks = block_obj ._mgr .blocks
3989
- blk_items = get_blk_items (block_obj ._mgr , blocks )
3991
+ blocks : List [ "Block" ] = list ( frame ._mgr .blocks )
3992
+ blk_items : List [ Index ] = get_blk_items (frame ._mgr )
3990
3993
3991
3994
if len (data_columns ):
3992
3995
axis , axis_labels = new_non_index_axes [0 ]
3993
3996
new_labels = Index (axis_labels ).difference (Index (data_columns ))
3994
- mgr = block_obj .reindex (new_labels , axis = axis )._mgr
3997
+ mgr = frame .reindex (new_labels , axis = axis )._mgr
3995
3998
3996
3999
blocks = list (mgr .blocks )
3997
- blk_items = get_blk_items (mgr , blocks )
4000
+ blk_items = get_blk_items (mgr )
3998
4001
for c in data_columns :
3999
- mgr = block_obj .reindex ([c ], axis = axis )._mgr
4002
+ mgr = frame .reindex ([c ], axis = axis )._mgr
4000
4003
blocks .extend (mgr .blocks )
4001
- blk_items .extend (get_blk_items (mgr , mgr . blocks ))
4004
+ blk_items .extend (get_blk_items (mgr ))
4002
4005
4003
4006
# reorder the blocks in the same order as the existing table if we can
4004
4007
if table_exists :
4005
4008
by_items = {
4006
4009
tuple (b_items .tolist ()): (b , b_items )
4007
4010
for b , b_items in zip (blocks , blk_items )
4008
4011
}
4009
- new_blocks = []
4012
+ new_blocks : List [ "Block" ] = []
4010
4013
new_blk_items = []
4011
4014
for ea in values_axes :
4012
4015
items = tuple (ea .values )
@@ -4875,7 +4878,7 @@ def _unconvert_index(
4875
4878
4876
4879
4877
4880
def _maybe_convert_for_string_atom (
4878
- name : str , block , existing_col , min_itemsize , nan_rep , encoding , errors
4881
+ name : str , block : "Block" , existing_col , min_itemsize , nan_rep , encoding , errors
4879
4882
):
4880
4883
if not block .is_object :
4881
4884
return block .values
@@ -4895,11 +4898,12 @@ def _maybe_convert_for_string_atom(
4895
4898
elif not (inferred_type == "string" or dtype_name == "object" ):
4896
4899
return block .values
4897
4900
4898
- block = block .fillna (nan_rep , downcast = False )
4899
- if isinstance (block , list ):
4900
- # Note: because block is always object dtype, fillna goes
4901
- # through a path such that the result is always a 1-element list
4902
- block = block [0 ]
4901
+ blocks : List ["Block" ] = block .fillna (nan_rep , downcast = False )
4902
+ # Note: because block is always object dtype, fillna goes
4903
+ # through a path such that the result is always a 1-element list
4904
+ assert len (blocks ) == 1
4905
+ block = blocks [0 ]
4906
+
4903
4907
data = block .values
4904
4908
4905
4909
# see if we have a valid string type
0 commit comments