Skip to content

Commit 1153c86

Browse files
committed
TST: Test DatetimeIndex weekend offset
1 parent e991141 commit 1153c86

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

pandas/tests/indexes/test_datetimelike.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from datetime import datetime, timedelta, time
3+
from datetime import datetime, timedelta, time, date
44

55
import numpy as np
66

@@ -348,6 +348,19 @@ def test_construction_outofbounds(self):
348348
# can't create DatetimeIndex
349349
DatetimeIndex(dates)
350350

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+
351364
def test_astype(self):
352365
# GH 13149, GH 13209
353366
idx = DatetimeIndex(['2016-05-16', 'NaT', NaT, np.NaN])
@@ -748,6 +761,22 @@ def test_difference_freq(self):
748761
tm.assert_index_equal(idx_diff, expected)
749762
tm.assert_attr_equal('freq', idx_diff, expected)
750763

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+
751780

752781
class TestPeriodIndex(DatetimeLike, tm.TestCase):
753782
_holder = PeriodIndex

0 commit comments

Comments
 (0)