4
4
from typing import (
5
5
TYPE_CHECKING ,
6
6
Sequence ,
7
+ cast ,
7
8
)
8
9
import warnings
9
10
@@ -220,23 +221,27 @@ def concatenate_managers(
220
221
return BlockManager ((nb ,), axes )
221
222
222
223
mgrs_indexers = _maybe_reindex_columns_na_proxy (axes , mgrs_indexers )
224
+ if len (mgrs_indexers ) == 1 :
225
+ mgr , indexers = mgrs_indexers [0 ]
226
+ # Assertion correct but disabled for perf:
227
+ # assert not indexers
228
+ if copy :
229
+ out = mgr .copy (deep = True )
230
+ else :
231
+ out = mgr .copy (deep = False )
232
+ out .axes = axes
233
+ return out
223
234
224
235
concat_plan = _get_combined_plan ([mgr for mgr , _ in mgrs_indexers ])
225
236
226
237
blocks = []
238
+ values : ArrayLike
227
239
228
240
for placement , join_units in concat_plan :
229
241
unit = join_units [0 ]
230
242
blk = unit .block
231
243
232
- if len (join_units ) == 1 :
233
- values = blk .values
234
- if copy :
235
- values = values .copy ()
236
- else :
237
- values = values .view ()
238
- fastpath = True
239
- elif _is_uniform_join_units (join_units ):
244
+ if _is_uniform_join_units (join_units ):
240
245
vals = [ju .block .values for ju in join_units ]
241
246
242
247
if not blk .is_extension :
@@ -527,8 +532,7 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
527
532
528
533
if upcasted_na is None and self .block .dtype .kind != "V" :
529
534
# No upcasting is necessary
530
- fill_value = self .block .fill_value
531
- values = self .block .values
535
+ return self .block .values
532
536
else :
533
537
fill_value = upcasted_na
534
538
@@ -540,30 +544,13 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
540
544
# we want to avoid filling with np.nan if we are
541
545
# using None; we already know that we are all
542
546
# nulls
543
- values = self .block .values . ravel ( order = "K" )
544
- if len ( values ) and values [0 ] is None :
547
+ values = cast ( np . ndarray , self .block .values )
548
+ if values . size and values [0 , 0 ] is None :
545
549
fill_value = None
546
550
547
551
return make_na_array (empty_dtype , self .block .shape , fill_value )
548
552
549
- if not self .block ._can_consolidate :
550
- # preserve these for validation in concat_compat
551
- return self .block .values
552
-
553
- if self .block .is_bool :
554
- # External code requested filling/upcasting, bool values must
555
- # be upcasted to object to avoid being upcasted to numeric.
556
- values = self .block .astype (np .dtype ("object" )).values
557
- else :
558
- # No dtype upcasting is done here, it will be performed during
559
- # concatenation itself.
560
- values = self .block .values
561
-
562
- # If there's no indexing to be done, we want to signal outside
563
- # code that this array must be copied explicitly. This is done
564
- # by returning a view and checking `retval.base`.
565
- values = values .view ()
566
- return values
553
+ return self .block .values
567
554
568
555
569
556
def _concatenate_join_units (join_units : list [JoinUnit ], copy : bool ) -> ArrayLike :
@@ -580,19 +567,7 @@ def _concatenate_join_units(join_units: list[JoinUnit], copy: bool) -> ArrayLike
580
567
for ju in join_units
581
568
]
582
569
583
- if len (to_concat ) == 1 :
584
- # Only one block, nothing to concatenate.
585
- concat_values = to_concat [0 ]
586
- if copy :
587
- if isinstance (concat_values , np .ndarray ):
588
- # non-reindexed (=not yet copied) arrays are made into a view
589
- # in JoinUnit.get_reindexed_values
590
- if concat_values .base is not None :
591
- concat_values = concat_values .copy ()
592
- else :
593
- concat_values = concat_values .copy ()
594
-
595
- elif any (is_1d_only_ea_dtype (t .dtype ) for t in to_concat ):
570
+ if any (is_1d_only_ea_dtype (t .dtype ) for t in to_concat ):
596
571
# TODO(EA2D): special case not needed if all EAs used HybridBlocks
597
572
598
573
# error: No overload variant of "__getitem__" of "ExtensionArray" matches
@@ -658,10 +633,6 @@ def _get_empty_dtype(join_units: Sequence[JoinUnit]) -> tuple[DtypeObj, DtypeObj
658
633
-------
659
634
dtype
660
635
"""
661
- if len (join_units ) == 1 :
662
- blk = join_units [0 ].block
663
- return blk .dtype , blk .dtype
664
-
665
636
if lib .dtypes_all_equal ([ju .block .dtype for ju in join_units ]):
666
637
empty_dtype = join_units [0 ].block .dtype
667
638
return empty_dtype , empty_dtype
@@ -722,7 +693,4 @@ def _is_uniform_join_units(join_units: list[JoinUnit]) -> bool:
722
693
# no blocks that would get missing values (can lead to type upcasts)
723
694
# unless we're an extension dtype.
724
695
all (not ju .is_na or ju .block .is_extension for ju in join_units )
725
- and
726
- # only use this path when there is something to concatenate
727
- len (join_units ) > 1
728
696
)
0 commit comments