@@ -586,7 +586,7 @@ class DataFrame(NDFrame, OpsMixin):
586
586
2 2 3
587
587
"""
588
588
589
- _internal_names_set = {"columns" , "index" } | NDFrame ._internal_names_set
589
+ _internal_names_set = {"_columns" , " columns" , "_index " , "index" } | NDFrame ._internal_names_set
590
590
_typ = "dataframe"
591
591
_HANDLED_TYPES = (Series , Index , ExtensionArray , np .ndarray )
592
592
_accessors : set [str ] = {"sparse" }
@@ -617,11 +617,20 @@ def __init__(
617
617
dtype = self ._validate_dtype (dtype )
618
618
619
619
if isinstance (data , DataFrame ):
620
+ if index is None and columns is None :
621
+ index = data .index
622
+ columns = data .columns
620
623
data = data ._mgr
621
624
622
625
if isinstance (data , (BlockManager , ArrayManager )):
623
626
# first check if a Manager is passed without any other arguments
624
627
# -> use fastpath (without checking Manager type)
628
+ if index is None or columns is None :
629
+ assert False
630
+ if not index .equals (data .axes [- 1 ]):#index is not data.axes[-1]:
631
+ assert False
632
+ if not columns .equals (data .axes [0 ]):#columns is not data.axes[0]:
633
+ assert False
625
634
if index is None and columns is None and dtype is None and not copy :
626
635
# GH#33357 fastpath
627
636
NDFrame .__init__ (self , data )
@@ -747,7 +756,7 @@ def __init__(
747
756
index , # type: ignore[arg-type]
748
757
dtype ,
749
758
)
750
- mgr = arrays_to_mgr (
759
+ mgr , _ , _ = arrays_to_mgr (
751
760
arrays ,
752
761
columns ,
753
762
index ,
@@ -790,7 +799,7 @@ def __init__(
790
799
construct_1d_arraylike_from_scalar (data , len (index ), dtype )
791
800
for _ in range (len (columns ))
792
801
]
793
- mgr = arrays_to_mgr (values , columns , index , dtype = None , typ = manager )
802
+ mgr , _ , _ = arrays_to_mgr (values , columns , index , dtype = None , typ = manager )
794
803
else :
795
804
arr2d = construct_2d_arraylike_from_scalar (
796
805
data ,
@@ -2354,9 +2363,10 @@ def maybe_reorder(
2354
2363
columns = columns .drop (exclude )
2355
2364
2356
2365
manager = get_option ("mode.data_manager" )
2357
- mgr = arrays_to_mgr (arrays , columns , result_index , typ = manager )
2366
+ mgr , index , columns = arrays_to_mgr (arrays , columns , result_index , typ = manager )
2358
2367
2359
- return cls (mgr )
2368
+ # FIXME: get axes without mgr.axes
2369
+ return cls (mgr , index = index , columns = columns )
2360
2370
2361
2371
def to_records (
2362
2372
self , index : bool = True , column_dtypes = None , index_dtypes = None
@@ -2558,15 +2568,15 @@ def _from_arrays(
2558
2568
columns = ensure_index (columns )
2559
2569
if len (columns ) != len (arrays ):
2560
2570
raise ValueError ("len(columns) must match len(arrays)" )
2561
- mgr = arrays_to_mgr (
2571
+ mgr , index , columns = arrays_to_mgr (
2562
2572
arrays ,
2563
2573
columns ,
2564
2574
index ,
2565
2575
dtype = dtype ,
2566
2576
verify_integrity = verify_integrity ,
2567
2577
typ = manager ,
2568
2578
)
2569
- return cls (mgr )
2579
+ return cls (mgr , index = index , columns = columns )
2570
2580
2571
2581
@doc (
2572
2582
storage_options = _shared_docs ["storage_options" ],
@@ -3683,7 +3693,7 @@ def _ixs(self, i: int, axis: int = 0) -> Series:
3683
3693
3684
3694
# if we are a copy, mark as such
3685
3695
copy = isinstance (new_mgr .array , np .ndarray ) and new_mgr .array .base is None
3686
- result = self ._constructor_sliced (new_mgr , name = self .index [i ]).__finalize__ (
3696
+ result = self ._constructor_sliced (new_mgr , index = self . columns , name = self .index [i ]).__finalize__ (
3687
3697
self
3688
3698
)
3689
3699
result ._set_is_copy (self , copy = copy )
@@ -4198,7 +4208,7 @@ def _box_col_values(self, values: SingleDataManager, loc: int) -> Series:
4198
4208
name = self .columns [loc ]
4199
4209
klass = self ._constructor_sliced
4200
4210
# We get index=self.index bc values is a SingleDataManager
4201
- return klass (values , name = name , fastpath = True ).__finalize__ (self )
4211
+ return klass (values , name = name , index = self . index , fastpath = True ).__finalize__ (self )
4202
4212
4203
4213
# ----------------------------------------------------------------------
4204
4214
# Lookup Caching
@@ -6884,8 +6894,12 @@ def sort_values( # type: ignore[override]
6884
6894
new_data .set_axis (
6885
6895
self ._get_block_manager_axis (axis ), default_index (len (indexer ))
6886
6896
)
6887
-
6888
- result = self ._constructor (new_data )
6897
+ # FIXME: get axes without mgr.axes
6898
+ axes_dict = {}
6899
+ axes_dict ["index" ] = new_data .axes [- 1 ]
6900
+ if self .ndim == 2 :
6901
+ axes_dict ["columns" ] = new_data .axes [0 ]
6902
+ result = self ._constructor (new_data , ** axes_dict )
6889
6903
if inplace :
6890
6904
return self ._update_inplace (result )
6891
6905
else :
@@ -7569,7 +7583,7 @@ def _dispatch_frame_op(self, right, func: Callable, axis: int | None = None):
7569
7583
# i.e. scalar, faster than checking np.ndim(right) == 0
7570
7584
with np .errstate (all = "ignore" ):
7571
7585
bm = self ._mgr .apply (array_op , right = right )
7572
- return self ._constructor (bm )
7586
+ return self ._constructor (bm , index = self . index , columns = self . columns )
7573
7587
7574
7588
elif isinstance (right , DataFrame ):
7575
7589
assert self .index .equals (right .index )
@@ -7590,7 +7604,7 @@ def _dispatch_frame_op(self, right, func: Callable, axis: int | None = None):
7590
7604
right ._mgr , # type: ignore[arg-type]
7591
7605
array_op ,
7592
7606
)
7593
- return self ._constructor (bm )
7607
+ return self ._constructor (bm , index = self . index , columns = self . columns )
7594
7608
7595
7609
elif isinstance (right , Series ) and axis == 1 :
7596
7610
# axis=1 means we want to operate row-by-row
@@ -10833,7 +10847,8 @@ def _get_data() -> DataFrame:
10833
10847
# After possibly _get_data and transposing, we are now in the
10834
10848
# simple case where we can use BlockManager.reduce
10835
10849
res , _ = df ._mgr .reduce (blk_func , ignore_failures = ignore_failures )
10836
- out = df ._constructor (res ).iloc [0 ]
10850
+ # FIXME: get axes without mgr.axes
10851
+ out = df ._constructor (res , index = res .axes [1 ], columns = res .axes [0 ]).iloc [0 ]
10837
10852
if out_dtype is not None :
10838
10853
out = out .astype (out_dtype )
10839
10854
if axis == 0 and len (self ) == 0 and name in ["sum" , "prod" ]:
@@ -11541,9 +11556,9 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame:
11541
11556
_info_axis_name = "columns"
11542
11557
11543
11558
index = properties .AxisProperty (
11544
- axis = 1 , doc = "The index (row labels) of the DataFrame."
11559
+ axis = 0 , doc = "The index (row labels) of the DataFrame."
11545
11560
)
11546
- columns = properties .AxisProperty (axis = 0 , doc = "The column labels of the DataFrame." )
11561
+ columns = properties .AxisProperty (axis = 1 , doc = "The column labels of the DataFrame." )
11547
11562
11548
11563
@property
11549
11564
def _AXIS_NUMBERS (self ) -> dict [str , int ]:
0 commit comments