Skip to content

Commit 95eb153

Browse files
authored
CLN: remove unused concat code (pandas-dev#43577)
1 parent 084c543 commit 95eb153

File tree

2 files changed

+6
-93
lines changed

2 files changed

+6
-93
lines changed

pandas/core/dtypes/missing.py

-38
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import pandas._libs.missing as libmissing
1313
from pandas._libs.tslibs import (
1414
NaT,
15-
Period,
1615
iNaT,
1716
)
1817
from pandas._typing import (
@@ -644,40 +643,3 @@ def is_valid_na_for_dtype(obj, dtype: DtypeObj) -> bool:
644643

645644
# fallback, default to allowing NaN, None, NA, NaT
646645
return not isinstance(obj, (np.datetime64, np.timedelta64, Decimal))
647-
648-
649-
def isna_all(arr: ArrayLike) -> bool:
650-
"""
651-
Optimized equivalent to isna(arr).all()
652-
"""
653-
total_len = len(arr)
654-
655-
# Usually it's enough to check but a small fraction of values to see if
656-
# a block is NOT null, chunks should help in such cases.
657-
# parameters 1000 and 40 were chosen arbitrarily
658-
chunk_len = max(total_len // 40, 1000)
659-
660-
dtype = arr.dtype
661-
if dtype.kind == "f":
662-
checker = nan_checker
663-
664-
elif dtype.kind in ["m", "M"] or dtype.type is Period:
665-
# error: Incompatible types in assignment (expression has type
666-
# "Callable[[Any], Any]", variable has type "ufunc")
667-
checker = lambda x: np.asarray(x.view("i8")) == iNaT # type: ignore[assignment]
668-
669-
else:
670-
# error: Incompatible types in assignment (expression has type "Callable[[Any],
671-
# Any]", variable has type "ufunc")
672-
checker = lambda x: _isna_array( # type: ignore[assignment]
673-
x, inf_as_na=INF_AS_NA
674-
)
675-
676-
return all(
677-
# error: Argument 1 to "__call__" of "ufunc" has incompatible type
678-
# "Union[ExtensionArray, Any]"; expected "Union[Union[int, float, complex, str,
679-
# bytes, generic], Sequence[Union[int, float, complex, str, bytes, generic]],
680-
# Sequence[Sequence[Any]], _SupportsArray]"
681-
checker(arr[i : i + chunk_len]).all() # type: ignore[arg-type]
682-
for i in range(0, total_len, chunk_len)
683-
)

pandas/core/internals/concat.py

+6-55
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
import numpy as np
1212

13-
from pandas._libs import (
14-
NaT,
15-
internals as libinternals,
16-
)
17-
from pandas._libs.missing import NA
13+
from pandas._libs import internals as libinternals
1814
from pandas._typing import (
1915
ArrayLike,
2016
DtypeObj,
@@ -32,14 +28,12 @@
3228
is_1d_only_ea_obj,
3329
is_datetime64tz_dtype,
3430
is_dtype_equal,
35-
needs_i8_conversion,
3631
)
3732
from pandas.core.dtypes.concat import (
3833
cast_to_common_type,
3934
concat_compat,
4035
)
4136
from pandas.core.dtypes.dtypes import ExtensionDtype
42-
from pandas.core.dtypes.missing import is_valid_na_for_dtype
4337

4438
import pandas.core.algorithms as algos
4539
from pandas.core.arrays import (
@@ -381,36 +375,6 @@ def dtype(self):
381375
return blk.dtype
382376
return ensure_dtype_can_hold_na(blk.dtype)
383377

384-
def _is_valid_na_for(self, dtype: DtypeObj) -> bool:
385-
"""
386-
Check that we are all-NA of a type/dtype that is compatible with this dtype.
387-
Augments `self.is_na` with an additional check of the type of NA values.
388-
"""
389-
if not self.is_na:
390-
return False
391-
if self.block.dtype.kind == "V":
392-
return True
393-
394-
if self.dtype == object:
395-
values = self.block.values
396-
return all(is_valid_na_for_dtype(x, dtype) for x in values.ravel(order="K"))
397-
398-
na_value = self.block.fill_value
399-
if na_value is NaT and not is_dtype_equal(self.dtype, dtype):
400-
# e.g. we are dt64 and other is td64
401-
# fill_values match but we should not cast self.block.values to dtype
402-
# TODO: this will need updating if we ever have non-nano dt64/td64
403-
return False
404-
405-
if na_value is NA and needs_i8_conversion(dtype):
406-
# FIXME: kludge; test_append_empty_frame_with_timedelta64ns_nat
407-
# e.g. self.dtype == "Int64" and dtype is td64, we dont want
408-
# to consider these as matching
409-
return False
410-
411-
# TODO: better to use can_hold_element?
412-
return is_valid_na_for_dtype(na_value, dtype)
413-
414378
@cache_readonly
415379
def is_na(self) -> bool:
416380
blk = self.block
@@ -421,24 +385,14 @@ def is_na(self) -> bool:
421385
def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
422386
values: ArrayLike
423387

424-
if upcasted_na is None and self.block.dtype.kind != "V":
388+
if upcasted_na is None and not self.is_na:
425389
# No upcasting is necessary
426390
fill_value = self.block.fill_value
427391
values = self.block.get_values()
428392
else:
429393
fill_value = upcasted_na
430394

431-
if self._is_valid_na_for(empty_dtype):
432-
# note: always holds when self.block.dtype.kind == "V"
433-
blk_dtype = self.block.dtype
434-
435-
if blk_dtype == np.dtype("object"):
436-
# we want to avoid filling with np.nan if we are
437-
# using None; we already know that we are all
438-
# nulls
439-
values = self.block.values.ravel(order="K")
440-
if len(values) and values[0] is None:
441-
fill_value = None
395+
if self.is_na:
442396

443397
if is_datetime64tz_dtype(empty_dtype):
444398
i8values = np.full(self.shape, fill_value.value)
@@ -507,8 +461,7 @@ def _concatenate_join_units(
507461

508462
empty_dtype = _get_empty_dtype(join_units)
509463

510-
has_none_blocks = any(unit.block.dtype.kind == "V" for unit in join_units)
511-
upcasted_na = _dtype_to_na_value(empty_dtype, has_none_blocks)
464+
upcasted_na = _dtype_to_na_value(empty_dtype)
512465

513466
to_concat = [
514467
ju.get_reindexed_values(empty_dtype=empty_dtype, upcasted_na=upcasted_na)
@@ -548,7 +501,7 @@ def _concatenate_join_units(
548501
return concat_values
549502

550503

551-
def _dtype_to_na_value(dtype: DtypeObj, has_none_blocks: bool):
504+
def _dtype_to_na_value(dtype: DtypeObj):
552505
"""
553506
Find the NA value to go with this dtype.
554507
"""
@@ -587,11 +540,9 @@ def _get_empty_dtype(join_units: Sequence[JoinUnit]) -> DtypeObj:
587540
empty_dtype = join_units[0].block.dtype
588541
return empty_dtype
589542

590-
has_none_blocks = any(unit.block.dtype.kind == "V" for unit in join_units)
543+
has_none_blocks = any(unit.is_na for unit in join_units)
591544

592545
dtypes = [unit.dtype for unit in join_units if not unit.is_na]
593-
if not len(dtypes):
594-
dtypes = [unit.dtype for unit in join_units if unit.block.dtype.kind != "V"]
595546

596547
dtype = find_common_type(dtypes)
597548
if has_none_blocks:

0 commit comments

Comments
 (0)