Skip to content

Commit dafe7f0

Browse files
authored
CLN: unnecessary checks in internals.concat (#41189)
1 parent e37bea5 commit dafe7f0

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

pandas/core/internals/concat.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
import pandas.core.algorithms as algos
4545
from pandas.core.arrays import (
46-
Categorical,
4746
DatetimeArray,
4847
ExtensionArray,
4948
)
@@ -193,17 +192,17 @@ def concatenate_managers(
193192
blocks = []
194193

195194
for placement, join_units in concat_plan:
195+
unit = join_units[0]
196+
blk = unit.block
196197

197198
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
200200
if copy:
201201
values = values.copy()
202202
else:
203203
values = values.view()
204-
b = b.make_block_same_class(values, placement=placement)
204+
fastpath = True
205205
elif _is_uniform_join_units(join_units):
206-
blk = join_units[0].block
207206
vals = [ju.block.values for ju in join_units]
208207

209208
if not blk.is_extension:
@@ -218,14 +217,16 @@ def concatenate_managers(
218217

219218
values = ensure_wrapped_if_datetimelike(values)
220219

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)
226227
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+
229230
blocks.append(b)
230231

231232
return BlockManager(tuple(blocks), axes)
@@ -445,12 +446,10 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
445446
# preserve these for validation in concat_compat
446447
return self.block.values
447448

448-
if self.block.is_bool and not isinstance(self.block.values, Categorical):
449+
if self.block.is_bool:
449450
# External code requested filling/upcasting, bool values must
450451
# be upcasted to object to avoid being upcasted to numeric.
451452
values = self.block.astype(np.object_).values
452-
elif self.block.is_extension:
453-
values = self.block.values
454453
else:
455454
# No dtype upcasting is done here, it will be performed during
456455
# concatenation itself.
@@ -533,9 +532,11 @@ def _dtype_to_na_value(dtype: DtypeObj, has_none_blocks: bool):
533532
elif dtype.kind in ["f", "c"]:
534533
return dtype.type("NaN")
535534
elif dtype.kind == "b":
535+
# different from missing.na_value_for_dtype
536536
return None
537537
elif dtype.kind in ["i", "u"]:
538538
if not has_none_blocks:
539+
# different from missing.na_value_for_dtype
539540
return None
540541
return np.nan
541542
elif dtype.kind == "O":

0 commit comments

Comments
 (0)