Skip to content

Commit a3a2ee2

Browse files
committed
Return dtype, not type
1 parent 7a587f6 commit a3a2ee2

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

pandas/core/dtypes/cast.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ def infer_dtype_from_array(arr, pandas_dtype=False):
483483
return arr.dtype, arr
484484

485485

486-
def _maybe_infer_dtype_type(element):
487-
"""Try to infer an object's dtype's type, for use in arithmetic ops
486+
def maybe_infer_dtype_type(element):
487+
"""Try to infer an object's dtype, for use in arithmetic ops
488488
489489
Uses `element.dtype` if that's available.
490490
Objects implementing the iterator protocol are cast to a NumPy array,
@@ -503,16 +503,16 @@ def _maybe_infer_dtype_type(element):
503503
Examples
504504
--------
505505
>>> from collections import namedtuple
506-
>>> Foo = namedtuple("dtype")
507-
>>> _maybe_infer_dtype_type(Foo(np.dtype("i8")))
506+
>>> Foo = namedtuple("Foo", "dtype")
507+
>>> maybe_infer_dtype_type(Foo(np.dtype("i8")))
508508
numpy.int64
509509
"""
510510
tipo = None
511511
if hasattr(element, 'dtype'):
512-
tipo = element.dtype.type
512+
tipo = element.dtype
513513
elif is_list_like(element):
514514
element = np.asarray(element)
515-
tipo = element.dtype.type
515+
tipo = element.dtype
516516
return tipo
517517

518518

pandas/core/internals.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
maybe_convert_objects,
4646
astype_nansafe,
4747
find_common_type,
48-
_maybe_infer_dtype_type)
48+
maybe_infer_dtype_type)
4949
from pandas.core.dtypes.missing import (
5050
isna, notna, array_equivalent,
5151
_isna_compat,
@@ -630,9 +630,9 @@ def convert(self, copy=True, **kwargs):
630630
def _can_hold_element(self, element):
631631
""" require the same dtype as ourselves """
632632
dtype = self.values.dtype.type
633-
tipo = _maybe_infer_dtype_type(element)
633+
tipo = maybe_infer_dtype_type(element)
634634
if tipo:
635-
return issubclass(tipo, dtype)
635+
return issubclass(tipo.type, dtype)
636636
return isinstance(element, dtype)
637637

638638
def _try_cast_result(self, result, dtype=None):
@@ -1806,10 +1806,10 @@ class FloatBlock(FloatOrComplexBlock):
18061806
_downcast_dtype = 'int64'
18071807

18081808
def _can_hold_element(self, element):
1809-
tipo = _maybe_infer_dtype_type(element)
1809+
tipo = maybe_infer_dtype_type(element)
18101810
if tipo:
1811-
return (issubclass(tipo, (np.floating, np.integer)) and
1812-
not issubclass(tipo, (np.datetime64, np.timedelta64)))
1811+
return (issubclass(tipo.type, (np.floating, np.integer)) and
1812+
not issubclass(tipo.type, (np.datetime64, np.timedelta64)))
18131813
return (isinstance(element, (float, int, np.floating, np.int_)) and
18141814
not isinstance(element, (bool, np.bool_, datetime, timedelta,
18151815
np.datetime64, np.timedelta64)))
@@ -1855,9 +1855,9 @@ class ComplexBlock(FloatOrComplexBlock):
18551855
is_complex = True
18561856

18571857
def _can_hold_element(self, element):
1858-
tipo = _maybe_infer_dtype_type(element)
1858+
tipo = maybe_infer_dtype_type(element)
18591859
if tipo:
1860-
return issubclass(tipo,
1860+
return issubclass(tipo.type,
18611861
(np.floating, np.integer, np.complexfloating))
18621862
return (isinstance(element,
18631863
(float, int, complex, np.float_, np.int_)) and
@@ -1873,11 +1873,12 @@ class IntBlock(NumericBlock):
18731873
_can_hold_na = False
18741874

18751875
def _can_hold_element(self, element):
1876-
tipo = _maybe_infer_dtype_type(element)
1876+
tipo = maybe_infer_dtype_type(element)
18771877
if tipo:
1878-
return (issubclass(tipo, np.integer) and
1879-
not issubclass(tipo, (np.datetime64, np.timedelta64)) and
1880-
self.dtype.itemsize >= element.dtype.itemsize)
1878+
return (issubclass(tipo.type, np.integer) and
1879+
not issubclass(tipo.type, (np.datetime64,
1880+
np.timedelta64)) and
1881+
self.dtype.itemsize >= tipo.itemsize)
18811882
return is_integer(element)
18821883

18831884
def should_store(self, value):
@@ -1915,9 +1916,9 @@ def _box_func(self):
19151916
return lambda x: tslib.Timedelta(x, unit='ns')
19161917

19171918
def _can_hold_element(self, element):
1918-
tipo = _maybe_infer_dtype_type(element)
1919+
tipo = maybe_infer_dtype_type(element)
19191920
if tipo:
1920-
return issubclass(tipo, np.timedelta64)
1921+
return issubclass(tipo.type, np.timedelta64)
19211922
return isinstance(element, (timedelta, np.timedelta64))
19221923

19231924
def fillna(self, value, **kwargs):
@@ -2015,9 +2016,9 @@ class BoolBlock(NumericBlock):
20152016
_can_hold_na = False
20162017

20172018
def _can_hold_element(self, element):
2018-
tipo = _maybe_infer_dtype_type(element)
2019+
tipo = maybe_infer_dtype_type(element)
20192020
if tipo:
2020-
return issubclass(tipo, np.bool_)
2021+
return issubclass(tipo.type, np.bool_)
20212022
return isinstance(element, (bool, np.bool_))
20222023

20232024
def should_store(self, value):
@@ -2447,7 +2448,7 @@ def _astype(self, dtype, mgr=None, **kwargs):
24472448
return super(DatetimeBlock, self)._astype(dtype=dtype, **kwargs)
24482449

24492450
def _can_hold_element(self, element):
2450-
tipo = _maybe_infer_dtype_type(element)
2451+
tipo = maybe_infer_dtype_type(element)
24512452
if tipo:
24522453
# TODO: this still uses asarray, instead of dtype.type
24532454
element = np.array(element)

0 commit comments

Comments
 (0)