-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Open
Labels
ConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancement
Description
xref #9133, maybe allow a dict of dtypes to be passed as well
I trying to use the dtype argument in the DataFrame constructor to set the types of several columns, and I'm getting incorrect types. Everything works well, however, when the dtypes come from the recarray itself.
In [61]:
data = [(1,1.2), (2,2.3)]
dtype = [('a','i4'),('b','f4')]
a = np.array(data, dtype=dtype)
pd.DataFrame(a).dtypes
Out [61]:
a int32
b float32
dtype: object
But if I use the dtype constructor argument, I get incorrect types:
In [65]:
pd.DataFrame(data, dtype=dtype).dtypes
Out [65]:
0 object
1 object
dtype: object
The astype() member function doesn't work either:
In [75]:
pd.DataFrame(data).astype(dtype)
Truncated Traceback (Use C-c C-x to view full TB):
c:\Anaconda\lib\site-packages\pandas\core\common.pyc in take_nd(arr, indexer, axis, out, fill_value, mask_info, allow_fill)
491 indexer = _ensure_int64(indexer)
492 if not allow_fill:
--> 493 dtype, fill_value = arr.dtype, arr.dtype.type()
494 mask_info = None, False
495 else:
TypeError: function takes exactly 1 argument (0 given)
I'm using Pandas 0.11.0 from Anaconda.
Thanks in advance.
nickeubank, donutsonhudson, Seanny123, lafrech, jesse-git and 15 more
Metadata
Metadata
Assignees
Labels
ConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsEnhancement