Skip to content

Commit 71f6008

Browse files
committed
added tests and modified preprocessing code
1 parent 6c99a1b commit 71f6008

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pandas/tools/tests/test_tile.py

+23
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,29 @@ def test_datetime_cut(self):
294294
).astype("category", ordered=True)
295295
tm.assert_series_equal(result, expected)
296296

297+
def test_datetime_list_cut(self):
298+
# GH 14714
299+
data = [np.datetime64('2013-01-01'), np.datetime64('2013-01-02'),
300+
np.datetime64('2013-01-03')]
301+
result, bins = cut(data, 3, retbins=True)
302+
expected = Series(['(2012-12-31 23:57:07.200000, 2013-01-01 16:00:00]',
303+
'(2013-01-01 16:00:00, 2013-01-02 08:00:00]',
304+
'(2013-01-02 08:00:00, 2013-01-03 00:00:00]'],
305+
).astype("category", ordered=True)
306+
tm.assert_almost_equal(Series(result), expected)
307+
308+
def test_datetime_ndarray_cut(self):
309+
# GH 14714
310+
data = np.array([np.datetime64('2013-01-01'),
311+
np.datetime64('2013-01-02'),
312+
np.datetime64('2013-01-03')])
313+
result, bins = cut(data, 3, retbins=True)
314+
expected = Series(['(2012-12-31 23:57:07.200000, 2013-01-01 16:00:00]',
315+
'(2013-01-01 16:00:00, 2013-01-02 08:00:00]',
316+
'(2013-01-02 08:00:00, 2013-01-03 00:00:00]'],
317+
).astype("category", ordered=True)
318+
tm.assert_almost_equal(Series(result), expected)
319+
297320

298321
def curpath():
299322
pth, _ = os.path.split(os.path.abspath(__file__))

pandas/tools/tile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ def _coerce_to_type(x):
314314
dtype = None
315315
original = x
316316
if is_timedelta64_dtype(x):
317-
x = x.view(np.int64)
317+
x = to_timedelta(x).view(np.int64)
318318
dtype = np.timedelta64
319319

320320
elif is_datetime64_dtype(x):
321-
x = x.view(np.int64)
321+
x = to_datetime(x).view(np.int64)
322322
dtype = np.datetime64
323323
return original, x, dtype
324324

0 commit comments

Comments
 (0)