8080if TYPE_CHECKING :
8181 from tables import Col , File , Node
8282
83+ from pandas .core .internals import Block
84+
8385
8486# versioning attribute
8587_version = "0.15.2"
@@ -3860,20 +3862,17 @@ def _create_axes(
38603862 for a in new_non_index_axes :
38613863 obj = _reindex_axis (obj , a [0 ], a [1 ])
38623864
3863- def get_blk_items (mgr , blocks ):
3864- return [mgr .items .take (blk .mgr_locs ) for blk in blocks ]
3865-
38663865 transposed = new_index .axis == 1
38673866
38683867 # figure out data_columns and get out blocks
38693868 data_columns = self .validate_data_columns (
38703869 data_columns , min_itemsize , new_non_index_axes
38713870 )
38723871
3873- block_obj = self .get_object (obj , transposed )._consolidate ()
3872+ frame = self .get_object (obj , transposed )._consolidate ()
38743873
38753874 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
38773876 )
38783877
38793878 # add my values
@@ -3978,35 +3977,39 @@ def get_blk_items(mgr, blocks):
39783977
39793978 @staticmethod
39803979 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 ,
39823985 ):
39833986 # Helper to clarify non-state-altering parts of _create_axes
39843987
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 ]
39873990
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 )
39903993
39913994 if len (data_columns ):
39923995 axis , axis_labels = new_non_index_axes [0 ]
39933996 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
39953998
39963999 blocks = list (mgr .blocks )
3997- blk_items = get_blk_items (mgr , blocks )
4000+ blk_items = get_blk_items (mgr )
39984001 for c in data_columns :
3999- mgr = block_obj .reindex ([c ], axis = axis )._mgr
4002+ mgr = frame .reindex ([c ], axis = axis )._mgr
40004003 blocks .extend (mgr .blocks )
4001- blk_items .extend (get_blk_items (mgr , mgr . blocks ))
4004+ blk_items .extend (get_blk_items (mgr ))
40024005
40034006 # reorder the blocks in the same order as the existing table if we can
40044007 if table_exists :
40054008 by_items = {
40064009 tuple (b_items .tolist ()): (b , b_items )
40074010 for b , b_items in zip (blocks , blk_items )
40084011 }
4009- new_blocks = []
4012+ new_blocks : List [ "Block" ] = []
40104013 new_blk_items = []
40114014 for ea in values_axes :
40124015 items = tuple (ea .values )
@@ -4875,7 +4878,7 @@ def _unconvert_index(
48754878
48764879
48774880def _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
48794882):
48804883 if not block .is_object :
48814884 return block .values
@@ -4895,11 +4898,12 @@ def _maybe_convert_for_string_atom(
48954898 elif not (inferred_type == "string" or dtype_name == "object" ):
48964899 return block .values
48974900
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+
49034907 data = block .values
49044908
49054909 # see if we have a valid string type
0 commit comments