@@ -563,39 +563,55 @@ def __init__(
563
563
if isinstance (data , DataFrame ):
564
564
data = data ._mgr
565
565
566
- if isinstance (data , (BlockManager , ArrayManager )):
567
- if index is None and columns is None and dtype is None and copy is False :
568
- # GH#33357 fastpath
569
- NDFrame .__init__ (self , data )
570
- return
566
+ # first check if a Manager is passed without any other arguments
567
+ # -> use fastpath (without checking Manager type)
568
+ if (
569
+ index is None
570
+ and columns is None
571
+ and dtype is None
572
+ and copy is False
573
+ and isinstance (data , (BlockManager , ArrayManager ))
574
+ ):
575
+ # GH#33357 fastpath
576
+ NDFrame .__init__ (self , data )
577
+ return
571
578
579
+ manager = get_option ("mode.data_manager" )
580
+
581
+ if isinstance (data , (BlockManager , ArrayManager )):
572
582
mgr = self ._init_mgr (
573
583
data , axes = {"index" : index , "columns" : columns }, dtype = dtype , copy = copy
574
584
)
575
585
576
586
elif isinstance (data , dict ):
577
- mgr = dict_to_mgr (data , index , columns , dtype = dtype )
587
+ mgr = dict_to_mgr (data , index , columns , dtype = dtype , typ = manager )
578
588
elif isinstance (data , ma .MaskedArray ):
579
589
import numpy .ma .mrecords as mrecords
580
590
581
591
# masked recarray
582
592
if isinstance (data , mrecords .MaskedRecords ):
583
- mgr = rec_array_to_mgr (data , index , columns , dtype , copy )
593
+ mgr = rec_array_to_mgr (data , index , columns , dtype , copy , typ = manager )
584
594
585
595
# a masked array
586
596
else :
587
597
data = sanitize_masked_array (data )
588
- mgr = ndarray_to_mgr (data , index , columns , dtype = dtype , copy = copy )
598
+ mgr = ndarray_to_mgr (
599
+ data , index , columns , dtype = dtype , copy = copy , typ = manager
600
+ )
589
601
590
602
elif isinstance (data , (np .ndarray , Series , Index )):
591
603
if data .dtype .names :
592
604
# i.e. numpy structured array
593
- mgr = rec_array_to_mgr (data , index , columns , dtype , copy )
605
+ mgr = rec_array_to_mgr (data , index , columns , dtype , copy , typ = manager )
594
606
elif getattr (data , "name" , None ) is not None :
595
607
# i.e. Series/Index with non-None name
596
- mgr = dict_to_mgr ({data .name : data }, index , columns , dtype = dtype )
608
+ mgr = dict_to_mgr (
609
+ {data .name : data }, index , columns , dtype = dtype , typ = manager
610
+ )
597
611
else :
598
- mgr = ndarray_to_mgr (data , index , columns , dtype = dtype , copy = copy )
612
+ mgr = ndarray_to_mgr (
613
+ data , index , columns , dtype = dtype , copy = copy , typ = manager
614
+ )
599
615
600
616
# For data is list-like, or Iterable (will consume into list)
601
617
elif is_list_like (data ):
@@ -610,11 +626,15 @@ def __init__(
610
626
arrays , columns , index = nested_data_to_arrays (
611
627
data , columns , index , dtype
612
628
)
613
- mgr = arrays_to_mgr (arrays , columns , index , columns , dtype = dtype )
629
+ mgr = arrays_to_mgr (
630
+ arrays , columns , index , columns , dtype = dtype , typ = manager
631
+ )
614
632
else :
615
- mgr = ndarray_to_mgr (data , index , columns , dtype = dtype , copy = copy )
633
+ mgr = ndarray_to_mgr (
634
+ data , index , columns , dtype = dtype , copy = copy , typ = manager
635
+ )
616
636
else :
617
- mgr = dict_to_mgr ({}, index , columns , dtype = dtype )
637
+ mgr = dict_to_mgr ({}, index , columns , dtype = dtype , typ = manager )
618
638
# For data is scalar
619
639
else :
620
640
if index is None or columns is None :
@@ -631,18 +651,19 @@ def __init__(
631
651
construct_1d_arraylike_from_scalar (data , len (index ), dtype )
632
652
for _ in range (len (columns ))
633
653
]
634
- mgr = arrays_to_mgr (values , columns , index , columns , dtype = None )
654
+ mgr = arrays_to_mgr (
655
+ values , columns , index , columns , dtype = None , typ = manager
656
+ )
635
657
else :
636
658
values = construct_2d_arraylike_from_scalar (
637
659
data , len (index ), len (columns ), dtype , copy
638
660
)
639
661
640
662
mgr = ndarray_to_mgr (
641
- values , index , columns , dtype = values .dtype , copy = False
663
+ values , index , columns , dtype = values .dtype , copy = False , typ = manager
642
664
)
643
665
644
666
# ensure correct Manager type according to settings
645
- manager = get_option ("mode.data_manager" )
646
667
mgr = mgr_to_mgr (mgr , typ = manager )
647
668
648
669
NDFrame .__init__ (self , mgr )
@@ -1970,7 +1991,8 @@ def from_records(
1970
1991
arr_columns = arr_columns .drop (arr_exclude )
1971
1992
columns = columns .drop (exclude )
1972
1993
1973
- mgr = arrays_to_mgr (arrays , arr_columns , result_index , columns )
1994
+ manager = get_option ("mode.data_manager" )
1995
+ mgr = arrays_to_mgr (arrays , arr_columns , result_index , columns , typ = manager )
1974
1996
1975
1997
return cls (mgr )
1976
1998
@@ -2177,13 +2199,15 @@ def _from_arrays(
2177
2199
if dtype is not None :
2178
2200
dtype = pandas_dtype (dtype )
2179
2201
2202
+ manager = get_option ("mode.data_manager" )
2180
2203
mgr = arrays_to_mgr (
2181
2204
arrays ,
2182
2205
columns ,
2183
2206
index ,
2184
2207
columns ,
2185
2208
dtype = dtype ,
2186
2209
verify_integrity = verify_integrity ,
2210
+ typ = manager ,
2187
2211
)
2188
2212
return cls (mgr )
2189
2213
0 commit comments