2
2
import pytest
3
3
4
4
from pandas import DataFrame , Series , Timestamp , date_range , to_datetime
5
+
5
6
import pandas ._testing as tm
6
7
8
+ import pandas .util .testing as tm
9
+ import warnings
10
+
11
+ warnings .simplefilter ("error" )
12
+
13
+
7
14
8
15
@pytest .fixture
9
16
def date_range_frame ():
@@ -24,14 +31,18 @@ def test_basic(self, date_range_frame):
24
31
df .loc [15 :30 , "A" ] = np .nan
25
32
dates = date_range ("1/1/1990" , periods = N * 3 , freq = "25s" )
26
33
27
- result = df .asof (dates )
28
- assert result .notna ().all (1 ).all ()
29
- lb = df .index [14 ]
30
- ub = df .index [30 ]
34
+ with warnings .catch_warnings ():
35
+ warnings .simplefilter ("ignore" , FutureWarning )
36
+
37
+ result = df .asof (dates )
38
+ assert result .notna ().all (1 ).all ()
39
+ lb = df .index [14 ]
40
+ ub = df .index [30 ]
31
41
32
- dates = list (dates )
33
- result = df .asof (dates )
34
- assert result .notna ().all (1 ).all ()
42
+ dates = list (dates )
43
+
44
+ result = df .asof (dates )
45
+ assert result .notna ().all (1 ).all ()
35
46
36
47
mask = (result .index >= lb ) & (result .index < ub )
37
48
rs = result [mask ]
@@ -43,40 +54,46 @@ def test_subset(self, date_range_frame):
43
54
df .loc [4 :8 , "A" ] = np .nan
44
55
dates = date_range ("1/1/1990" , periods = N * 3 , freq = "25s" )
45
56
46
- # with a subset of A should be the same
47
- result = df .asof (dates , subset = "A" )
48
- expected = df .asof (dates )
49
- tm .assert_frame_equal (result , expected )
57
+ with warnings .catch_warnings ():
58
+ warnings .simplefilter ("ignore" , FutureWarning )
50
59
51
- # same with A/B
52
- result = df .asof (dates , subset = [ "A" , "B" ] )
53
- expected = df .asof (dates )
54
- tm .assert_frame_equal (result , expected )
60
+ # with a subset of A should be the same
61
+ result = df .asof (dates , subset = "A" )
62
+ expected = df .asof (dates )
63
+ tm .assert_frame_equal (result , expected )
55
64
56
- # B gives df.asof
57
- result = df .asof (dates , subset = "B" )
58
- expected = df .resample ( "25s" , closed = "right" ). ffill (). reindex (dates )
59
- expected . iloc [ 20 :] = 9
65
+ # same with A/B
66
+ result = df .asof (dates , subset = [ "A" , "B" ] )
67
+ expected = df .asof (dates )
68
+ tm . assert_frame_equal ( result , expected )
60
69
61
- tm .assert_frame_equal (result , expected )
70
+ # B gives df.asof
71
+ result = df .asof (dates , subset = "B" )
72
+ expected = df .resample ("25s" , closed = "right" ).ffill ().reindex (dates )
73
+ expected .iloc [20 :] = 9
74
+
75
+ tm .assert_frame_equal (result , expected )
62
76
63
77
def test_missing (self , date_range_frame ):
64
78
# GH 15118
65
79
# no match found - `where` value before earliest date in index
66
80
N = 10
67
81
df = date_range_frame .iloc [:N ].copy ()
68
- result = df .asof ("1989-12-31" )
82
+ with warnings .catch_warnings ():
83
+ warnings .simplefilter ("ignore" , FutureWarning )
69
84
70
- expected = Series (
71
- index = ["A" , "B" ], name = Timestamp ("1989-12-31" ), dtype = np .float64
72
- )
73
- tm .assert_series_equal (result , expected )
85
+ result = df .asof ("1989-12-31" )
74
86
75
- result = df .asof (to_datetime (["1989-12-31" ]))
76
- expected = DataFrame (
77
- index = to_datetime (["1989-12-31" ]), columns = ["A" , "B" ], dtype = "float64"
78
- )
79
- tm .assert_frame_equal (result , expected )
87
+ expected = Series (
88
+ index = ["A" , "B" ], name = Timestamp ("1989-12-31" ), dtype = np .float64
89
+ )
90
+ tm .assert_series_equal (result , expected )
91
+
92
+ result = df .asof (to_datetime (["1989-12-31" ]))
93
+ expected = DataFrame (
94
+ index = to_datetime (["1989-12-31" ]), columns = ["A" , "B" ], dtype = "float64"
95
+ )
96
+ tm .assert_frame_equal (result , expected )
80
97
81
98
def test_all_nans (self , date_range_frame ):
82
99
# GH 15713
@@ -132,5 +149,8 @@ def test_time_zone_aware_index(self, stamp, expected):
132
149
Timestamp ("2018-01-01 22:35:10.550+00:00" ),
133
150
],
134
151
)
135
- result = df .asof (stamp )
136
- tm .assert_series_equal (result , expected )
152
+ with warnings .catch_warnings ():
153
+ warnings .simplefilter ("ignore" , FutureWarning )
154
+
155
+ result = df .asof (stamp )
156
+ tm .assert_series_equal (result , expected )
0 commit comments