Skip to content

Commit 04e720f

Browse files
authored
PERF: concat (#43354)
1 parent 7e8331b commit 04e720f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

pandas/core/internals/concat.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
is_1d_only_ea_obj,
3333
is_datetime64tz_dtype,
3434
is_dtype_equal,
35+
is_scalar,
3536
needs_i8_conversion,
3637
)
3738
from pandas.core.dtypes.concat import (
@@ -41,6 +42,7 @@
4142
from pandas.core.dtypes.dtypes import ExtensionDtype
4243
from pandas.core.dtypes.missing import (
4344
is_valid_na_for_dtype,
45+
isna,
4446
isna_all,
4547
)
4648

@@ -396,22 +398,32 @@ def _is_valid_na_for(self, dtype: DtypeObj) -> bool:
396398

397399
@cache_readonly
398400
def is_na(self) -> bool:
399-
if self.block is None:
401+
blk = self.block
402+
if blk is None:
400403
return True
401404

402-
if not self.block._can_hold_na:
405+
if not blk._can_hold_na:
403406
return False
404407

405-
values = self.block.values
406-
if isinstance(self.block.values.dtype, SparseDtype):
408+
values = blk.values
409+
if values.size == 0:
410+
return True
411+
if isinstance(values.dtype, SparseDtype):
407412
return False
408-
elif self.block.is_extension:
413+
414+
if values.ndim == 1:
409415
# TODO(EA2D): no need for special case with 2D EAs
410-
values_flat = values
416+
val = values[0]
417+
if not is_scalar(val) or not isna(val):
418+
# ideally isna_all would do this short-circuiting
419+
return False
420+
return isna_all(values)
411421
else:
412-
values_flat = values.ravel(order="K")
413-
414-
return isna_all(values_flat)
422+
val = values[0][0]
423+
if not is_scalar(val) or not isna(val):
424+
# ideally isna_all would do this short-circuiting
425+
return False
426+
return all(isna_all(row) for row in values)
415427

416428
def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
417429
if upcasted_na is None:
@@ -578,6 +590,7 @@ def _get_empty_dtype(join_units: Sequence[JoinUnit]) -> DtypeObj:
578590
blk = join_units[0].block
579591
if blk is None:
580592
return np.dtype(np.float64)
593+
return blk.dtype
581594

582595
if _is_uniform_reindex(join_units):
583596
# FIXME: integrate property

0 commit comments

Comments
 (0)