4
4
5
5
import inspect
6
6
7
+ from pandas .errors import Pandas4Warning
7
8
from pandas .util ._decorators import deprecate_nonkeyword_arguments
8
9
9
10
import pandas ._testing as tm
10
11
12
+ WARNING_CATEGORY = Pandas4Warning
13
+
11
14
12
15
@deprecate_nonkeyword_arguments (
13
- version = "1.1" , allowed_args = ["a" , "b" ], name = "f_add_inputs" , klass = FutureWarning
16
+ WARNING_CATEGORY , allowed_args = ["a" , "b" ], name = "f_add_inputs"
14
17
)
15
18
def f (a , b = 0 , c = 0 , d = 0 ):
16
19
return a + b + c + d
@@ -41,25 +44,25 @@ def test_two_and_two_arguments():
41
44
42
45
43
46
def test_three_arguments ():
44
- with tm .assert_produces_warning (FutureWarning ):
47
+ with tm .assert_produces_warning (WARNING_CATEGORY ):
45
48
assert f (6 , 3 , 3 ) == 12
46
49
47
50
48
51
def test_four_arguments ():
49
- with tm .assert_produces_warning (FutureWarning ):
52
+ with tm .assert_produces_warning (WARNING_CATEGORY ):
50
53
assert f (1 , 2 , 3 , 4 ) == 10
51
54
52
55
53
56
def test_three_arguments_with_name_in_warning ():
54
57
msg = (
55
- "Starting with pandas version 1.1 all arguments of f_add_inputs "
58
+ "Starting with pandas version 4.0 all arguments of f_add_inputs "
56
59
"except for the arguments 'a' and 'b' will be keyword-only."
57
60
)
58
- with tm .assert_produces_warning (FutureWarning , match = msg ):
61
+ with tm .assert_produces_warning (WARNING_CATEGORY , match = msg ):
59
62
assert f (6 , 3 , 3 ) == 12
60
63
61
64
62
- @deprecate_nonkeyword_arguments (version = "1.1" , klass = FutureWarning )
65
+ @deprecate_nonkeyword_arguments (WARNING_CATEGORY )
63
66
def g (a , b = 0 , c = 0 , d = 0 ):
64
67
with tm .assert_produces_warning (None ):
65
68
return a + b + c + d
@@ -75,20 +78,20 @@ def test_one_and_three_arguments_default_allowed_args():
75
78
76
79
77
80
def test_three_arguments_default_allowed_args ():
78
- with tm .assert_produces_warning (FutureWarning ):
81
+ with tm .assert_produces_warning (WARNING_CATEGORY ):
79
82
assert g (6 , 3 , 3 ) == 12
80
83
81
84
82
85
def test_three_positional_argument_with_warning_message_analysis ():
83
86
msg = (
84
- "Starting with pandas version 1.1 all arguments of g "
87
+ "Starting with pandas version 4.0 all arguments of g "
85
88
"except for the argument 'a' will be keyword-only."
86
89
)
87
- with tm .assert_produces_warning (FutureWarning , match = msg ):
90
+ with tm .assert_produces_warning (WARNING_CATEGORY , match = msg ):
88
91
assert g (6 , 3 , 3 ) == 12
89
92
90
93
91
- @deprecate_nonkeyword_arguments (version = "1.1" , klass = FutureWarning )
94
+ @deprecate_nonkeyword_arguments (WARNING_CATEGORY )
92
95
def h (a = 0 , b = 0 , c = 0 , d = 0 ):
93
96
return a + b + c + d
94
97
@@ -103,17 +106,17 @@ def test_all_keyword_arguments():
103
106
104
107
105
108
def test_one_positional_argument ():
106
- with tm .assert_produces_warning (FutureWarning ):
109
+ with tm .assert_produces_warning (WARNING_CATEGORY ):
107
110
assert h (23 ) == 23
108
111
109
112
110
113
def test_one_positional_argument_with_warning_message_analysis ():
111
- msg = "Starting with pandas version 1.1 all arguments of h will be keyword-only."
112
- with tm .assert_produces_warning (FutureWarning , match = msg ):
114
+ msg = "Starting with pandas version 4.0 all arguments of h will be keyword-only."
115
+ with tm .assert_produces_warning (WARNING_CATEGORY , match = msg ):
113
116
assert h (19 ) == 19
114
117
115
118
116
- @deprecate_nonkeyword_arguments (version = "1.1" , klass = UserWarning )
119
+ @deprecate_nonkeyword_arguments (WARNING_CATEGORY )
117
120
def i (a = 0 , / , b = 0 , * , c = 0 , d = 0 ):
118
121
return a + b + c + d
119
122
@@ -123,14 +126,12 @@ def test_i_signature():
123
126
124
127
125
128
def test_i_warns_klass ():
126
- with tm .assert_produces_warning (UserWarning ):
129
+ with tm .assert_produces_warning (WARNING_CATEGORY ):
127
130
assert i (1 , 2 ) == 3
128
131
129
132
130
133
class Foo :
131
- @deprecate_nonkeyword_arguments (
132
- version = None , allowed_args = ["self" , "bar" ], klass = FutureWarning
133
- )
134
+ @deprecate_nonkeyword_arguments (WARNING_CATEGORY , allowed_args = ["self" , "bar" ])
134
135
def baz (self , bar = None , foobar = None ): ...
135
136
136
137
@@ -140,8 +141,8 @@ def test_foo_signature():
140
141
141
142
def test_class ():
142
143
msg = (
143
- r"In a future version of pandas all arguments of Foo\.baz "
144
+ r"Starting with pandas version 4.0 all arguments of Foo\.baz "
144
145
r"except for the argument \'bar\' will be keyword-only"
145
146
)
146
- with tm .assert_produces_warning (FutureWarning , match = msg ):
147
+ with tm .assert_produces_warning (WARNING_CATEGORY , match = msg ):
147
148
Foo ().baz ("qux" , "quox" )
0 commit comments