6262 IndexKeyFunc ,
6363 IndexLabel ,
6464 Level ,
65+ Manager ,
6566 PythonFuncType ,
6667 Renamer ,
6768 StorageOptions ,
137138)
138139from pandas .core .indexes .multi import MultiIndex , maybe_droplevels
139140from pandas .core .indexing import check_bool_indexer , convert_to_index_sliceable
140- from pandas .core .internals import BlockManager
141+ from pandas .core .internals import ArrayManager , BlockManager
141142from pandas .core .internals .construction import (
142143 arrays_to_mgr ,
143144 dataclasses_to_dicts ,
144145 init_dict ,
145146 init_ndarray ,
146147 masked_rec_array_to_mgr ,
148+ mgr_to_mgr ,
147149 nested_data_to_arrays ,
148150 reorder_arrays ,
149151 sanitize_index ,
@@ -523,7 +525,7 @@ def __init__(
523525 if isinstance (data , DataFrame ):
524526 data = data ._mgr
525527
526- if isinstance (data , BlockManager ):
528+ if isinstance (data , ( BlockManager , ArrayManager ) ):
527529 if index is None and columns is None and dtype is None and copy is False :
528530 # GH#33357 fastpath
529531 NDFrame .__init__ (self , data )
@@ -601,8 +603,31 @@ def __init__(
601603 values , index , columns , dtype = values .dtype , copy = False
602604 )
603605
606+ # ensure correct Manager type according to settings
607+ manager = get_option ("mode.data_manager" )
608+ mgr = mgr_to_mgr (mgr , typ = manager )
609+
604610 NDFrame .__init__ (self , mgr )
605611
612+ def _as_manager (self , typ : str ) -> DataFrame :
613+ """
614+ Private helper function to create a DataFrame with specific manager.
615+
616+ Parameters
617+ ----------
618+ typ : {"block", "array"}
619+
620+ Returns
621+ -------
622+ DataFrame
623+ New DataFrame using specified manager type. Is not guaranteed
624+ to be a copy or not.
625+ """
626+ new_mgr : Manager
627+ new_mgr = mgr_to_mgr (self ._mgr , typ = typ )
628+ # fastpath of passing a manager doesn't check the option/manager class
629+ return DataFrame (new_mgr )
630+
606631 # ----------------------------------------------------------------------
607632
608633 @property
@@ -675,6 +700,8 @@ def _is_homogeneous_type(self) -> bool:
675700 ... "B": np.array([1, 2], dtype=np.int64)})._is_homogeneous_type
676701 False
677702 """
703+ if isinstance (self ._mgr , ArrayManager ):
704+ return len ({arr .dtype for arr in self ._mgr .arrays }) == 1
678705 if self ._mgr .any_extension_types :
679706 return len ({block .dtype for block in self ._mgr .blocks }) == 1
680707 else :
@@ -685,6 +712,8 @@ def _can_fast_transpose(self) -> bool:
685712 """
686713 Can we transpose this DataFrame without creating any new array objects.
687714 """
715+ if isinstance (self ._mgr , ArrayManager ):
716+ return False
688717 if self ._mgr .any_extension_types :
689718 # TODO(EA2D) special case would be unnecessary with 2D EAs
690719 return False
@@ -5506,7 +5535,7 @@ def sort_values( # type: ignore[override]
55065535 )
55075536
55085537 if ignore_index :
5509- new_data .axes [ 1 ] = ibase .default_index (len (indexer ))
5538+ new_data .set_axis ( 1 , ibase .default_index (len (indexer ) ))
55105539
55115540 result = self ._constructor (new_data )
55125541 if inplace :
@@ -6051,7 +6080,10 @@ def _dispatch_frame_op(self, right, func, axis: Optional[int] = None):
60516080 # fails in cases with empty columns reached via
60526081 # _frame_arith_method_with_reindex
60536082
6054- bm = self ._mgr .operate_blockwise (right ._mgr , array_op )
6083+ # TODO operate_blockwise expects a manager of the same type
6084+ bm = self ._mgr .operate_blockwise (
6085+ right ._mgr , array_op # type: ignore[arg-type]
6086+ )
60556087 return type (self )(bm )
60566088
60576089 elif isinstance (right , Series ) and axis == 1 :
@@ -8894,11 +8926,11 @@ def func(values: np.ndarray):
88948926 # We only use this in the case that operates on self.values
88958927 return op (values , axis = axis , skipna = skipna , ** kwds )
88968928
8897- def blk_func (values ):
8929+ def blk_func (values , axis = 1 ):
88988930 if isinstance (values , ExtensionArray ):
88998931 return values ._reduce (name , skipna = skipna , ** kwds )
89008932 else :
8901- return op (values , axis = 1 , skipna = skipna , ** kwds )
8933+ return op (values , axis = axis , skipna = skipna , ** kwds )
89028934
89038935 def _get_data () -> DataFrame :
89048936 if filter_type is None :
0 commit comments