@@ -218,9 +218,42 @@ cdef _try_infer_map(v):
218
218
return None
219
219
220
220
221
- def infer_dtype (object _values ):
221
+ def infer_dtype (object value ):
222
222
"""
223
- we are coercing to an ndarray here
223
+ Effeciently infer the type of a passed val, or list-like
224
+ array of values. Return a string describing the type.
225
+
226
+ Parameters
227
+ ----------
228
+ value : scalar, list, ndarray, or pandas type
229
+
230
+ Returns
231
+ -------
232
+ string describing the common type of the input data.
233
+ Results can include:
234
+ - floating
235
+ - integer
236
+ - mixed-integer
237
+ - mixed-integer-float
238
+ - complex
239
+ - categorical
240
+ - boolean
241
+ - datetime64
242
+ - datetime
243
+ - date
244
+ - timedelta64
245
+ - timedelta
246
+ - time
247
+ - period
248
+ - string
249
+ - unicode
250
+ - bytes
251
+ - mixed
252
+
253
+ Raises
254
+ ------
255
+ TypeError if ndarray-like but cannot infer the dtype
256
+
224
257
"""
225
258
226
259
cdef:
@@ -229,27 +262,27 @@ def infer_dtype(object _values):
229
262
ndarray values
230
263
bint seen_pdnat = False , seen_val = False
231
264
232
- if isinstance (_values , np.ndarray):
233
- values = _values
234
- elif hasattr (_values , ' dtype' ):
265
+ if isinstance (value , np.ndarray):
266
+ values = value
267
+ elif hasattr (value , ' dtype' ):
235
268
236
269
# this will handle ndarray-like
237
270
# e.g. categoricals
238
271
try :
239
- values = getattr (_values , ' _values' , getattr (
240
- _values , ' values' , _values ))
272
+ values = getattr (value , ' _values' , getattr (
273
+ value , ' values' , value ))
241
274
except :
242
- val = _try_infer_map(_values )
243
- if val is not None :
244
- return val
275
+ value = _try_infer_map(value )
276
+ if value is not None :
277
+ return value
245
278
246
279
# its ndarray like but we can't handle
247
- raise ValueError (" cannot infer type for {0}" .format(type (_values )))
280
+ raise ValueError (" cannot infer type for {0}" .format(type (value )))
248
281
249
282
else :
250
- if not isinstance (_values , list ):
251
- _values = list (_values )
252
- values = list_to_object_array(_values )
283
+ if not isinstance (value , list ):
284
+ value = list (value )
285
+ values = list_to_object_array(value )
253
286
254
287
values = getattr (values, ' values' , values)
255
288
val = _try_infer_map(values)
0 commit comments