Skip to content

BUG: when trying to use an out-of-bounds date as an object dtype (GH5312) #5322

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
Oct 25, 2013
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 @@ -636,6 +636,7 @@ Bug Fixes
- Fix ``Series.isin`` with date/time-like dtypes (:issue:`5021`)
- C and Python Parser can now handle the more common multi-index column format
which doesn't have a row for index names (:issue:`4702`)
- Bug when trying to use an out-of-bounds date as an object dtype (:issue:`5312`)

pandas 0.12.0
-------------
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,14 +1789,15 @@ def make_block(values, items, ref_items, klass=None, ndim=None, dtype=None, fast
if np.prod(values.shape):
flat = values.ravel()
inferred_type = lib.infer_dtype(flat)
if inferred_type == 'datetime':
if inferred_type in ['datetime','datetime64']:

# we have an object array that has been inferred as datetime, so
# convert it
try:
values = tslib.array_to_datetime(
flat).reshape(values.shape)
klass = DatetimeBlock
if issubclass(values.dtype.type, np.datetime64):
klass = DatetimeBlock
except: # it already object, so leave it
pass

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ def test_constructor_dtype_datetime64(self):
self.assertRaises(
TypeError, lambda x: Series(dates, dtype='datetime64'))

# invalid dates can be help as object
result = Series([datetime(2,1,1)])
self.assert_(result[0] == datetime(2,1,1,0,0))

result = Series([datetime(3000,1,1)])
self.assert_(result[0] == datetime(3000,1,1,0,0))

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