|
32 | 32 | is_1d_only_ea_obj,
|
33 | 33 | is_datetime64tz_dtype,
|
34 | 34 | is_dtype_equal,
|
| 35 | + is_scalar, |
35 | 36 | needs_i8_conversion,
|
36 | 37 | )
|
37 | 38 | from pandas.core.dtypes.concat import (
|
|
41 | 42 | from pandas.core.dtypes.dtypes import ExtensionDtype
|
42 | 43 | from pandas.core.dtypes.missing import (
|
43 | 44 | is_valid_na_for_dtype,
|
| 45 | + isna, |
44 | 46 | isna_all,
|
45 | 47 | )
|
46 | 48 |
|
@@ -396,22 +398,32 @@ def _is_valid_na_for(self, dtype: DtypeObj) -> bool:
|
396 | 398 |
|
397 | 399 | @cache_readonly
|
398 | 400 | def is_na(self) -> bool:
|
399 |
| - if self.block is None: |
| 401 | + blk = self.block |
| 402 | + if blk is None: |
400 | 403 | return True
|
401 | 404 |
|
402 |
| - if not self.block._can_hold_na: |
| 405 | + if not blk._can_hold_na: |
403 | 406 | return False
|
404 | 407 |
|
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): |
407 | 412 | return False
|
408 |
| - elif self.block.is_extension: |
| 413 | + |
| 414 | + if values.ndim == 1: |
409 | 415 | # 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) |
411 | 421 | 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) |
415 | 427 |
|
416 | 428 | def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
|
417 | 429 | if upcasted_na is None:
|
@@ -578,6 +590,7 @@ def _get_empty_dtype(join_units: Sequence[JoinUnit]) -> DtypeObj:
|
578 | 590 | blk = join_units[0].block
|
579 | 591 | if blk is None:
|
580 | 592 | return np.dtype(np.float64)
|
| 593 | + return blk.dtype |
581 | 594 |
|
582 | 595 | if _is_uniform_reindex(join_units):
|
583 | 596 | # FIXME: integrate property
|
|
0 commit comments