@@ -1367,7 +1367,7 @@ cdef object _try_infer_map(object dtype):
1367
1367
cdef:
1368
1368
object val
1369
1369
str attr
1370
- for attr in [" name " , " kind " , " base" , " type" ]:
1370
+ for attr in [" kind " , " name " , " base" , " type" ]:
1371
1371
val = getattr (dtype, attr, None )
1372
1372
if val in _TYPE_MAP:
1373
1373
return _TYPE_MAP[val]
@@ -1486,23 +1486,17 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
1486
1486
1487
1487
if util.is_array(value ):
1488
1488
values = value
1489
- elif hasattr (value, " inferred_type" ) and skipna is False :
1489
+ elif hasattr (type ( value) , " inferred_type" ) and skipna is False :
1490
1490
# Index, use the cached attribute if possible, populate the cache otherwise
1491
1491
return value.inferred_type
1492
1492
elif hasattr (value, " dtype" ):
1493
- # this will handle ndarray-like
1494
- # e.g. categoricals
1495
- dtype = value.dtype
1496
- if not cnp.PyArray_DescrCheck(dtype):
1497
- # i.e. not isinstance(dtype, np.dtype)
1498
- inferred = _try_infer_map(value.dtype)
1499
- if inferred is not None :
1500
- return inferred
1493
+ inferred = _try_infer_map(value.dtype)
1494
+ if inferred is not None :
1495
+ return inferred
1496
+ elif not cnp.PyArray_DescrCheck(value.dtype):
1501
1497
return " unknown-array"
1502
-
1503
1498
# Unwrap Series/Index
1504
1499
values = np.asarray(value)
1505
-
1506
1500
else :
1507
1501
if not isinstance (value, list ):
1508
1502
value = list (value)
@@ -1512,10 +1506,10 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
1512
1506
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
1513
1507
values = construct_1d_object_array_from_listlike(value)
1514
1508
1515
- val = _try_infer_map(values.dtype)
1516
- if val is not None :
1509
+ inferred = _try_infer_map(values.dtype)
1510
+ if inferred is not None :
1517
1511
# Anything other than object-dtype should return here.
1518
- return val
1512
+ return inferred
1519
1513
1520
1514
if values.descr.type_num != NPY_OBJECT:
1521
1515
# i.e. values.dtype != np.object_
0 commit comments