Skip to content

BUG: GH3416 properly convert np.datetime64 objects in the _possibily_convert_datetimes #3496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ pandas 0.11.1
- Duplicate indexes with getitem will return items in the correct order (GH3455_, GH3457_)
- Fix sorting in a frame with a list of columns which contains datetime64[ns] dtypes (GH3461_)
- DataFrames fetched via FRED now handle '.' as a NaN. (GH3469_)
- Properly convert np.datetime64 objects in a Series (GH3416_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH3416: https://github.com/pydata/pandas/issues/3416
.. _GH3251: https://github.com/pydata/pandas/issues/3251
.. _GH3379: https://github.com/pydata/pandas/issues/3379
.. _GH3454: https://github.com/pydata/pandas/issues/3454
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,12 +1119,12 @@ def _possibly_cast_to_datetime(value, dtype, coerce = False):
v = [ v ]
if len(v):
inferred_type = lib.infer_dtype(v)
if inferred_type == 'datetime':
if inferred_type in ['datetime','datetime64']:
try:
value = tslib.array_to_datetime(np.array(v))
except:
pass
elif inferred_type == 'timedelta':
elif inferred_type in ['timedelta','timedelta64']:
value = _possibly_cast_to_timedelta(value)

return value
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,20 @@ def test_constructor_dtype_datetime64(self):
self.assert_(isnull(s[1]) == True)
self.assert_(s.dtype == 'M8[ns]')

# GH3416
import pdb; pdb.set_trace()
dates = [
np.datetime64(datetime(2013, 1, 1)),
np.datetime64(datetime(2013, 1, 2)),
np.datetime64(datetime(2013, 1, 3)),
]

s = Series(dates)
self.assert_(s.dtype == 'M8[ns]')

s.ix[0] = np.nan
self.assert_(s.dtype == 'M8[ns]')

def test_constructor_dict(self):
d = {'a': 0., 'b': 1., 'c': 2.}
result = Series(d, index=['b', 'c', 'd', 'a'])
Expand Down