@@ -52,33 +52,46 @@ def test_nonzero_single_element(self):
52
52
s = Series ([False ])
53
53
assert not s .bool ()
54
54
55
- msg = "The truth value of a Series is ambiguous"
55
+ @pytest .mark .parametrize ("data" , [np .nan , pd .NaT , True , False ])
56
+ def test_nonzero_single_element_raise_1 (self , data ):
56
57
# single item nan to raise
57
- for s in [Series ([np .nan ]), Series ([pd .NaT ]), Series ([True ]), Series ([False ])]:
58
- with pytest .raises (ValueError , match = msg ):
59
- bool (s )
58
+ series = Series ([data ])
59
+
60
+ msg = "The truth value of a Series is ambiguous"
61
+ with pytest .raises (ValueError , match = msg ):
62
+ bool (series )
63
+
64
+ @pytest .mark .parametrize ("data" , [np .nan , pd .NaT ])
65
+ def test_nonzero_single_element_raise_2 (self , data ):
66
+ series = Series ([data ])
60
67
61
68
msg = "bool cannot act on a non-boolean single element Series"
62
- for s in [Series ([np .nan ]), Series ([pd .NaT ])]:
63
- with pytest .raises (ValueError , match = msg ):
64
- s .bool ()
69
+ with pytest .raises (ValueError , match = msg ):
70
+ series .bool ()
65
71
72
+ @pytest .mark .parametrize ("data" , [(True , True ), (False , False )])
73
+ def test_nonzero_multiple_element_raise (self , data ):
66
74
# multiple bool are still an error
75
+ series = Series ([data ])
76
+
67
77
msg = "The truth value of a Series is ambiguous"
68
- for s in [Series ([True , True ]), Series ([False , False ])]:
69
- with pytest .raises (ValueError , match = msg ):
70
- bool (s )
71
- with pytest .raises (ValueError , match = msg ):
72
- s .bool ()
78
+ with pytest .raises (ValueError , match = msg ):
79
+ bool (series )
80
+ with pytest .raises (ValueError , match = msg ):
81
+ series .bool ()
73
82
83
+ @pytest .mark .parametrize ("data" , [1 , 0 , "a" , 0.0 ])
84
+ def test_nonbool_single_element_raise (self , data ):
74
85
# single non-bool are an error
75
- for s in [Series ([1 ]), Series ([0 ]), Series (["a" ]), Series ([0.0 ])]:
76
- msg = "The truth value of a Series is ambiguous"
77
- with pytest .raises (ValueError , match = msg ):
78
- bool (s )
79
- msg = "bool cannot act on a non-boolean single element Series"
80
- with pytest .raises (ValueError , match = msg ):
81
- s .bool ()
86
+ series = Series ([data ])
87
+
88
+ msg = "The truth value of a Series is ambiguous"
89
+ with pytest .raises (ValueError , match = msg ):
90
+ bool (series )
91
+
92
+ msg = "bool cannot act on a non-boolean single element Series"
93
+ with pytest .raises (ValueError , match = msg ):
94
+ series .bool ()
82
95
83
96
def test_metadata_propagation_indiv_resample (self ):
84
97
# resample
0 commit comments