|
12 | 12 | from pandas.core.algorithms import quantile
|
13 | 13 | from pandas.tools.tile import cut, qcut
|
14 | 14 | import pandas.tools.tile as tmod
|
15 |
| -from pandas import to_datetime, DatetimeIndex |
| 15 | +from pandas import to_datetime, DatetimeIndex, Timestamp |
16 | 16 |
|
17 | 17 |
|
18 | 18 | class TestCut(tm.TestCase):
|
@@ -315,14 +315,22 @@ def test_datetime_cut(self):
|
315 | 315 |
|
316 | 316 | def test_datetime_bin(self):
|
317 | 317 | data = [np.datetime64('2012-12-13'), np.datetime64('2012-12-15')]
|
318 |
| - bins = [np.datetime64('2012-12-12'), np.datetime64('2012-12-14'), |
319 |
| - np.datetime64('2012-12-16')] |
320 |
| - result = cut(data, bins=bins) |
321 |
| - |
| 318 | + bin_data = ['2012-12-12', '2012-12-14', '2012-12-16'] |
322 | 319 | expected = Series(['(2012-12-12 00:00:00, 2012-12-14 00:00:00]',
|
323 |
| - '(2012-12-14 00:00:00, 2012-12-16 00:00:00]'], |
| 320 | + '(2012-12-14 00:00:00, 2012-12-16 00:00:00]'], |
324 | 321 | ).astype("category", ordered=True)
|
325 | 322 |
|
| 323 | + for conv in [Timestamp, Timestamp, np.datetime64]: |
| 324 | + bins = [conv(v) for v in bin_data] |
| 325 | + result = cut(data, bins=bins) |
| 326 | + tm.assert_series_equal(Series(result), expected) |
| 327 | + |
| 328 | + bin_pydatetime = [Timestamp(v).to_pydatetime() for v in bin_data] |
| 329 | + result = cut(data, bins=bin_pydatetime) |
| 330 | + tm.assert_series_equal(Series(result), expected) |
| 331 | + |
| 332 | + bins = to_datetime(bin_data) |
| 333 | + result = cut(data, bins=bin_pydatetime) |
326 | 334 | tm.assert_series_equal(Series(result), expected)
|
327 | 335 |
|
328 | 336 |
|
|
0 commit comments