|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -from datetime import datetime, timedelta, time |
| 3 | +from datetime import datetime, timedelta, time, date |
4 | 4 |
|
5 | 5 | import numpy as np
|
6 | 6 |
|
@@ -348,6 +348,19 @@ def test_construction_outofbounds(self):
|
348 | 348 | # can't create DatetimeIndex
|
349 | 349 | DatetimeIndex(dates)
|
350 | 350 |
|
| 351 | + def test_construction_with_ndarray(self): |
| 352 | + # GH 5152 |
| 353 | + dates = [datetime(2013, 10, 7), |
| 354 | + datetime(2013, 10, 8), |
| 355 | + datetime(2013, 10, 9)] |
| 356 | + data = DatetimeIndex(dates, freq=pd.tseries.frequencies.BDay()).values |
| 357 | + result = DatetimeIndex(data, freq=pd.tseries.frequencies.BDay()) |
| 358 | + expected = DatetimeIndex(['2013-10-07', |
| 359 | + '2013-10-08', |
| 360 | + '2013-10-09'], |
| 361 | + freq='B') |
| 362 | + tm.assert_index_equal(result, expected) |
| 363 | + |
351 | 364 | def test_astype(self):
|
352 | 365 | # GH 13149, GH 13209
|
353 | 366 | idx = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN])
|
@@ -748,6 +761,22 @@ def test_difference_freq(self):
|
748 | 761 | tm.assert_index_equal(idx_diff, expected)
|
749 | 762 | tm.assert_attr_equal('freq', idx_diff, expected)
|
750 | 763 |
|
| 764 | + def test_week_of_month_frequency(self): |
| 765 | + # GH 5348: "ValueError: Could not evaluate WOM-1SUN" shouldn't raise |
| 766 | + d1 = date(2002, 9, 1) |
| 767 | + d2 = date(2013, 10, 27) |
| 768 | + d3 = date(2012, 9, 30) |
| 769 | + idx1 = DatetimeIndex([d1, d2]) |
| 770 | + idx2 = DatetimeIndex([d3]) |
| 771 | + result = idx1.append(idx2) |
| 772 | + expected = DatetimeIndex([d1, d2, d3]) |
| 773 | + tm.assert_index_equal(result, expected) |
| 774 | + # GH 5115 |
| 775 | + result = date_range("2013-1-1", periods=4, freq='WOM-1SAT') |
| 776 | + dates = ['2013-01-05', '2013-02-02', '2013-03-02', '2013-04-06'] |
| 777 | + expected = DatetimeIndex(dates, freq='WOM-1SAT') |
| 778 | + tm.assert_index_equal(result, expected) |
| 779 | + |
751 | 780 |
|
752 | 781 | class TestPeriodIndex(DatetimeLike, tm.TestCase):
|
753 | 782 | _holder = PeriodIndex
|
|
0 commit comments