CLN: replace _interleave_dtype with _find_common_type · pandas-dev/pandas@8d07cae (original) (raw)
`@@ -9,7 +9,8 @@
`
9
9
``
10
10
`from pandas.core.base import PandasObject
`
11
11
``
12
``
`-
from pandas.types.dtypes import DatetimeTZDtype, CategoricalDtype
`
``
12
`+
from pandas.types.dtypes import (ExtensionDtype, DatetimeTZDtype,
`
``
13
`+
CategoricalDtype)
`
13
14
`from pandas.types.common import (_TD_DTYPE, _NS_DTYPE,
`
14
15
`_ensure_int64, _ensure_platform_int,
`
15
16
`is_integer,
`
`@@ -4496,55 +4497,13 @@ def _interleaved_dtype(blocks):
`
4496
4497
`if not len(blocks):
`
4497
4498
`return None
`
4498
4499
``
4499
``
`-
counts = defaultdict(list)
`
4500
``
`-
for x in blocks:
`
4501
``
`-
counts[type(x)].append(x)
`
4502
``
-
4503
``
`-
have_int = len(counts[IntBlock]) > 0
`
4504
``
`-
have_bool = len(counts[BoolBlock]) > 0
`
4505
``
`-
have_object = len(counts[ObjectBlock]) > 0
`
4506
``
`-
have_float = len(counts[FloatBlock]) > 0
`
4507
``
`-
have_complex = len(counts[ComplexBlock]) > 0
`
4508
``
`-
have_dt64 = len(counts[DatetimeBlock]) > 0
`
4509
``
`-
have_dt64_tz = len(counts[DatetimeTZBlock]) > 0
`
4510
``
`-
have_td64 = len(counts[TimeDeltaBlock]) > 0
`
4511
``
`-
have_cat = len(counts[CategoricalBlock]) > 0
`
4512
``
`-
TODO: have_sparse is not used
`
4513
``
`-
have_sparse = len(counts[SparseBlock]) > 0 # noqa
`
4514
``
`-
have_numeric = have_float or have_complex or have_int
`
4515
``
`-
has_non_numeric = have_dt64 or have_dt64_tz or have_td64 or have_cat
`
4516
``
-
4517
``
`-
if (have_object or
`
4518
``
`-
(have_bool and
`
4519
``
`-
(have_numeric or have_dt64 or have_dt64_tz or have_td64)) or
`
4520
``
`-
(have_numeric and has_non_numeric) or have_cat or have_dt64 or
`
4521
``
`-
have_dt64_tz or have_td64):
`
4522
``
`-
return np.dtype(object)
`
4523
``
`-
elif have_bool:
`
4524
``
`-
return np.dtype(bool)
`
4525
``
`-
elif have_int and not have_float and not have_complex:
`
4526
``
`-
if we are mixing unsigned and signed, then return
`
4527
``
`-
the next biggest int type (if we can)
`
4528
``
`-
lcd = _find_common_type([b.dtype for b in counts[IntBlock]])
`
4529
``
`-
kinds = set([i.dtype.kind for i in counts[IntBlock]])
`
4530
``
`-
if len(kinds) == 1:
`
4531
``
`-
return lcd
`
4532
``
-
4533
``
`-
if lcd == 'uint64' or lcd == 'int64':
`
4534
``
`-
return np.dtype('int64')
`
4535
``
-
4536
``
`-
return 1 bigger on the itemsize if unsinged
`
4537
``
`-
if lcd.kind == 'u':
`
4538
``
`-
return np.dtype('int%s' % (lcd.itemsize * 8 * 2))
`
4539
``
`-
return lcd
`
4540
``
-
4541
``
`-
elif have_int and have_float and not have_complex:
`
4542
``
`-
return np.dtype('float64')
`
4543
``
`-
elif have_complex:
`
4544
``
`-
return np.dtype('c16')
`
4545
``
`-
else:
`
4546
``
`-
introspection_blks = counts[FloatBlock] + counts[SparseBlock]
`
4547
``
`-
return _find_common_type([b.dtype for b in introspection_blks])
`
``
4500
`+
dtype = _find_common_type([b.dtype for b in blocks])
`
``
4501
+
``
4502
`+
only numpy compat
`
``
4503
`+
if isinstance(dtype, ExtensionDtype):
`
``
4504
`+
dtype = np.object
`
``
4505
+
``
4506
`+
return dtype
`
4548
4507
``
4549
4508
``
4550
4509
`def _consolidate(blocks):
`