Skip to content

Commit e9ef522

Browse files
committed
TST: properly handle unit='ns' and object/int arrays
1 parent 286782d commit e9ef522

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pandas/io/tests/json/test_pandas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ def test_convert_dates(self):
614614

615615
df['foo'] = 1.
616616
json = df.to_json(date_unit='ns')
617+
617618
result = read_json(json, convert_dates=False)
618619
expected = df.copy()
619620
expected['date'] = expected['date'].values.view('i8')

pandas/tslib.pyx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,11 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'):
19891989

19901990
assert is_ignore or is_coerce or is_raise
19911991

1992+
if unit == 'ns':
1993+
if issubclass(values.dtype.type, np.integer):
1994+
return values.astype('M8[ns]')
1995+
return array_to_datetime(values.astype(object), errors=errors)
1996+
19921997
m = cast_from_unit(None, unit)
19931998

19941999
if is_raise:
@@ -2003,13 +2008,6 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'):
20032008
iresult[mask] = 0
20042009
except:
20052010

2006-
# we might have a directly convertible M8[ns]
2007-
if unit == 'ns':
2008-
try:
2009-
return values.astype('M8[ns]')
2010-
except:
2011-
pass
2012-
20132011
# we have nulls embedded
20142012
from pandas import isnull
20152013

0 commit comments

Comments
 (0)