43
43
44
44
import pandas .core .algorithms as algos
45
45
from pandas .core .arrays import (
46
- Categorical ,
47
46
DatetimeArray ,
48
47
ExtensionArray ,
49
48
)
@@ -193,17 +192,17 @@ def concatenate_managers(
193
192
blocks = []
194
193
195
194
for placement , join_units in concat_plan :
195
+ unit = join_units [0 ]
196
+ blk = unit .block
196
197
197
198
if len (join_units ) == 1 and not join_units [0 ].indexers :
198
- b = join_units [0 ].block
199
- values = b .values
199
+ values = blk .values
200
200
if copy :
201
201
values = values .copy ()
202
202
else :
203
203
values = values .view ()
204
- b = b . make_block_same_class ( values , placement = placement )
204
+ fastpath = True
205
205
elif _is_uniform_join_units (join_units ):
206
- blk = join_units [0 ].block
207
206
vals = [ju .block .values for ju in join_units ]
208
207
209
208
if not blk .is_extension :
@@ -218,14 +217,16 @@ def concatenate_managers(
218
217
219
218
values = ensure_wrapped_if_datetimelike (values )
220
219
221
- if blk .values .dtype == values .dtype :
222
- # Fast-path
223
- b = blk .make_block_same_class (values , placement = placement )
224
- else :
225
- b = new_block (values , placement = placement , ndim = blk .ndim )
220
+ fastpath = blk .values .dtype == values .dtype
221
+ else :
222
+ values = _concatenate_join_units (join_units , concat_axis , copy = copy )
223
+ fastpath = False
224
+
225
+ if fastpath :
226
+ b = blk .make_block_same_class (values , placement = placement )
226
227
else :
227
- new_values = _concatenate_join_units ( join_units , concat_axis , copy = copy )
228
- b = new_block ( new_values , placement = placement , ndim = len ( axes ))
228
+ b = new_block ( values , placement = placement , ndim = len ( axes ) )
229
+
229
230
blocks .append (b )
230
231
231
232
return BlockManager (tuple (blocks ), axes )
@@ -445,12 +446,10 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
445
446
# preserve these for validation in concat_compat
446
447
return self .block .values
447
448
448
- if self .block .is_bool and not isinstance ( self . block . values , Categorical ) :
449
+ if self .block .is_bool :
449
450
# External code requested filling/upcasting, bool values must
450
451
# be upcasted to object to avoid being upcasted to numeric.
451
452
values = self .block .astype (np .object_ ).values
452
- elif self .block .is_extension :
453
- values = self .block .values
454
453
else :
455
454
# No dtype upcasting is done here, it will be performed during
456
455
# concatenation itself.
@@ -533,9 +532,11 @@ def _dtype_to_na_value(dtype: DtypeObj, has_none_blocks: bool):
533
532
elif dtype .kind in ["f" , "c" ]:
534
533
return dtype .type ("NaN" )
535
534
elif dtype .kind == "b" :
535
+ # different from missing.na_value_for_dtype
536
536
return None
537
537
elif dtype .kind in ["i" , "u" ]:
538
538
if not has_none_blocks :
539
+ # different from missing.na_value_for_dtype
539
540
return None
540
541
return np .nan
541
542
elif dtype .kind == "O" :
0 commit comments