-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
DatetimeDatetime data dtypeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandas
Description
In [1]: from pandas import Series
In [3]: import numpy as np
In [4]: Series([], dtype=np.datetime64)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-139e5646d234> in <module>()
----> 1 Series([], dtype=np.datetime64)
/users/is/whughes/pyenvs/1c4f50ee0e346415/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
218 else:
219 data = _sanitize_array(data, index, dtype, copy,
--> 220 raise_cast_failure=True)
221
222 data = SingleBlockManager(data, index, fastpath=True)
/users/is/whughes/pyenvs/1c4f50ee0e346415/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
2564
2565 else:
-> 2566 subarr = _try_cast(data, False)
2567
2568 # scalar like
/users/is/whughes/pyenvs/1c4f50ee0e346415/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/series.py in _try_cast(arr, take_fast_path)
2509
2510 try:
-> 2511 arr = _possibly_cast_to_datetime(arr, dtype)
2512 subarr = pa.array(arr, dtype=dtype, copy=copy)
2513 except (ValueError, TypeError):
/users/is/whughes/pyenvs/1c4f50ee0e346415/lib/python2.7/site-packages/pandas-0.13.1-py2.7-linux-x86_64.egg/pandas/core/common.py in _possibly_cast_to_datetime(value, dtype, coerce)
1659 else:
1660 raise TypeError(
-> 1661 "cannot convert datetimelike to dtype [%s]" % dtype)
1662 elif is_timedelta64 and dtype != _TD_DTYPE:
1663 if dtype.name == 'timedelta64[ns]':
TypeError: cannot convert datetimelike to dtype [datetime64]
The following workaround works:
Series([], dtype=datetime)
but I would expect passing in the numpy type to work too.
Metadata
Metadata
Assignees
Labels
DatetimeDatetime data dtypeDatetime data dtypeDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversionsError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandas