-
Notifications
You must be signed in to change notification settings - Fork 34
/
test_bizdays_pandas.py
108 lines (80 loc) · 3.26 KB
/
test_bizdays_pandas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pytest
from bizdays import *
import pandas as pd
import numpy as np
@pytest.fixture()
def actual():
return Calendar(name="actual")
@pytest.fixture(autouse=True)
def setup_data():
set_option("mode", "pandas")
def test_isbizday_with_timestamp_and_nat(actual):
assert pd.isna(actual.isbizday(pd.NaT))
def test_isbizday_with_timestamp(actual):
dt = pd.to_datetime("2021-12-30")
assert actual.isbizday(dt)
dt = pd.Timestamp("2021-12-30")
assert actual.isbizday(dt)
def test_bizdays_with_timestamp(actual):
dt1 = pd.to_datetime("2021-12-30")
dt2 = pd.to_datetime("2021-12-30")
assert actual.bizdays(dt1, dt2) == 0
dt1 = pd.to_datetime("2021-12-29")
dt2 = pd.to_datetime("2021-12-30")
assert actual.bizdays(dt1, dt2) == 1
assert actual.bizdays(dt2, dt1) == -1
def test_adjust_with_timestamp(actual):
dt = pd.to_datetime("2021-12-30")
assert isinstance(actual.following(dt), pd.Timestamp)
assert actual.following(dt) == pd.Timestamp(dt.date())
assert actual.preceding(dt) == pd.Timestamp(dt.date())
assert actual.modified_following(dt) == pd.Timestamp(dt.date())
assert actual.modified_preceding(dt) == pd.Timestamp(dt.date())
def test_offset_with_timestamp(actual):
dt = pd.to_datetime("2021-01-01")
assert isinstance(actual.offset(dt, 5), pd.Timestamp)
assert actual.offset(dt, 5) == pd.to_datetime("2021-01-06")
def test_isbizday_with_datetimeindex(actual):
dt = pd.to_datetime(["2021-12-30", "2021-11-30"])
x = actual.isbizday(dt)
assert isinstance(x, np.ndarray)
assert np.all(x)
def test_isbizday_with_datetimeindex_and_nat(actual):
dt = pd.to_datetime(["2021-12-30", "2021-11-30", None])
x = actual.isbizday(dt)
assert isinstance(x, np.ndarray)
assert x[0]
assert pd.isna(x[2])
assert [pd.NaT] == [pd.NaT]
def test_bizdays_with_datetimeindex(actual):
dt1 = pd.to_datetime(["2021-12-30", "2021-11-30"])
dt2 = pd.to_datetime(["2021-12-30", "2021-11-30"])
x = actual.bizdays(dt1, dt2)
assert isinstance(x, np.ndarray)
assert np.all(x == np.array([0, 0]))
def test_adjust_with_datetimeindex(actual):
dt = pd.to_datetime(["2021-12-30", "2021-11-30"])
x = actual.following(dt)
assert isinstance(x, pd.DatetimeIndex)
assert all(actual.following(dt) == dt.date)
assert all(actual.preceding(dt) == dt.date)
assert all(actual.modified_following(dt) == dt.date)
assert all(actual.modified_preceding(dt) == dt.date)
def test_offset_with_datetimeindex(actual):
dt = pd.to_datetime(["2021-01-01", "2021-01-02"])
dts = pd.to_datetime(["2021-01-06", "2021-01-07"])
x = actual.offset(dt, 5)
assert isinstance(x, pd.DatetimeIndex)
assert all(x == dts)
dt = pd.to_datetime(["2021-01-01", "2021-01-02"])
dts = pd.to_datetime(["2021-01-06", "2021-01-08"])
assert all(actual.offset(dt, [5, 6]) == dts.date)
dt = pd.to_datetime("2021-01-01")
dts = pd.to_datetime(["2021-01-06", "2021-01-07"])
assert all(actual.offset(dt, [5, 6]) == dts.date)
def test_offset_with_datetimeindex_and_nat(actual):
dt = pd.to_datetime(["2021-01-01", "2021-01-02", pd.NaT])
x = actual.offset(dt, 5)
assert isinstance(x, type(dt))
def test_seq_return_datetimeindex(actual):
actual.seq("2014-01-02", "2014-01-07")