Skip to content

BUG: Regression from 0.13 in the treatment of numpy datetime64 non-ns dtypes in Series creation (GH6429) #6530

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

Merged
merged 1 commit into from
Mar 3, 2014
Merged
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ Bug Fixes
fail (:issue:`6445`).
- Bug in multi-axis indexing using ``.loc`` on non-unique indices (:issue:`6504`)
- Bug that caused _ref_locs corruption when slice indexing across columns axis of a DataFrame (:issue:`6525`)
- Regression from 0.13 in the treatmenet of numpy ``datetime64`` non-ns dtypes in Series creation (:issue:`6529`)

pandas 0.13.1
-------------
Expand Down
9 changes: 3 additions & 6 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def isnull(obj):

See also
--------
pandas.notnull: boolean inverse of pandas.isnull
pandas.notnull: boolean inverse of pandas.isnull
"""
return _isnull(obj)

Expand Down Expand Up @@ -272,7 +272,7 @@ def notnull(obj):
isnulled : array-like of bool or bool
Array or bool indicating whether an object is *not* null or if an array
is given which of the element is *not* null.

See also
--------
pandas.isnull : boolean inverse of pandas.notnull
Expand Down Expand Up @@ -1727,10 +1727,7 @@ def _possibly_cast_to_datetime(value, dtype, coerce=False):
dtype = value.dtype

if dtype.kind == 'M' and dtype != _NS_DTYPE:
try:
value = tslib.array_to_datetime(value)
except:
raise
value = value.astype(_NS_DTYPE)

elif dtype.kind == 'm' and dtype != _TD_DTYPE:
from pandas.tseries.timedeltas import \
Expand Down
19 changes: 19 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,25 @@ def test_constructor_dtype_datetime64(self):
self.assertEqual(result['a'], Timestamp('20130101'))
self.assertEqual(result['b'], 1)

# GH6529
# coerce datetime64 non-ns properly
dates = date_range('01-Jan-2015', '01-Dec-2015', freq='M')
values2 = dates.view(np.ndarray).astype('datetime64[ns]')
expected = Series(values2, dates)

# numpy < 1.7 is very odd about astyping
if not _np_version_under1p7:
for dtype in ['s','D','ms','us','ns']:
values1 = dates.view(np.ndarray).astype('M8[{0}]'.format(dtype))
result = Series(values1, dates)
assert_series_equal(result,expected)

# leave datetime.date alone
dates2 = np.array([ d.date() for d in dates.to_pydatetime() ],dtype=object)
series1 = Series(dates2, dates)
self.assert_numpy_array_equal(series1.values,dates2)
self.assertEqual(series1.dtype,object)

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