@@ -25,19 +25,22 @@ def test_tab_completion(self):
25
25
assert "dt" not in dir (s )
26
26
assert "cat" not in dir (s )
27
27
28
+ def test_tab_completion_dt (self ):
28
29
# similarly for .dt
29
30
s = Series (date_range ("1/1/2015" , periods = 5 ))
30
31
assert "dt" in dir (s )
31
32
assert "str" not in dir (s )
32
33
assert "cat" not in dir (s )
33
34
35
+ def test_tab_completion_cat (self ):
34
36
# Similarly for .cat, but with the twist that str and dt should be
35
37
# there if the categories are of that type first cat and str.
36
38
s = Series (list ("abbcd" ), dtype = "category" )
37
39
assert "cat" in dir (s )
38
40
assert "str" in dir (s ) # as it is a string categorical
39
41
assert "dt" not in dir (s )
40
42
43
+ def test_tab_completion_cat_str (self ):
41
44
# similar to cat and str
42
45
s = Series (date_range ("1/1/2015" , periods = 5 )).astype ("category" )
43
46
assert "cat" in dir (s )
@@ -60,12 +63,8 @@ def test_tab_completion_with_categorical(self):
60
63
"as_unordered" ,
61
64
]
62
65
63
- def get_dir (s ):
64
- results = [r for r in s .cat .__dir__ () if not r .startswith ("_" )]
65
- return sorted (set (results ))
66
-
67
66
s = Series (list ("aabbcde" )).astype ("category" )
68
- results = get_dir ( s )
67
+ results = sorted ({ r for r in s . cat . __dir__ () if not r . startswith ( "_" )} )
69
68
tm .assert_almost_equal (results , sorted (set (ok_for_cat )))
70
69
71
70
@pytest .mark .parametrize (
@@ -98,14 +97,11 @@ def test_index_tab_completion(self, index):
98
97
else :
99
98
assert x not in dir_s
100
99
101
- def test_not_hashable (self ):
102
- s_empty = Series (dtype = object )
103
- s = Series ([1 ])
100
+ @pytest .mark .parametrize ("ser" , [Series (dtype = object ), Series ([1 ])])
101
+ def test_not_hashable (self , ser ):
104
102
msg = "unhashable type: 'Series'"
105
103
with pytest .raises (TypeError , match = msg ):
106
- hash (s_empty )
107
- with pytest .raises (TypeError , match = msg ):
108
- hash (s )
104
+ hash (ser )
109
105
110
106
def test_contains (self , datetime_series ):
111
107
tm .assert_contains_all (datetime_series .index , datetime_series )
@@ -138,12 +134,14 @@ def f(x):
138
134
expected = tsdf .max ()
139
135
tm .assert_series_equal (result , expected )
140
136
137
+ def test_ndarray_compat_like_func (self ):
141
138
# using an ndarray like function
142
139
s = Series (np .random .randn (10 ))
143
140
result = Series (np .ones_like (s ))
144
141
expected = Series (1 , index = range (10 ), dtype = "float64" )
145
142
tm .assert_series_equal (result , expected )
146
143
144
+ def test_ndarray_compat_ravel (self ):
147
145
# ravel
148
146
s = Series (np .random .randn (10 ))
149
147
tm .assert_almost_equal (s .ravel (order = "F" ), s .values .ravel (order = "F" ))
@@ -152,15 +150,15 @@ def test_empty_method(self):
152
150
s_empty = Series (dtype = object )
153
151
assert s_empty .empty
154
152
155
- s2 = Series (index = [1 ], dtype = object )
156
- for full_series in [Series ([1 ]), s2 ]:
157
- assert not full_series .empty
153
+ @pytest .mark .parametrize ("dtype" , ["int64" , object ])
154
+ def test_empty_method_full_series (self , dtype ):
155
+ full_series = Series (index = [1 ], dtype = dtype )
156
+ assert not full_series .empty
158
157
159
- def test_integer_series_size (self ):
158
+ @pytest .mark .parametrize ("dtype" , [None , "Int64" ])
159
+ def test_integer_series_size (self , dtype ):
160
160
# GH 25580
161
- s = Series (range (9 ))
162
- assert s .size == 9
163
- s = Series (range (9 ), dtype = "Int64" )
161
+ s = Series (range (9 ), dtype = dtype )
164
162
assert s .size == 9
165
163
166
164
def test_attrs (self ):
@@ -186,19 +184,22 @@ def test_unknown_attribute(self):
186
184
with pytest .raises (AttributeError , match = msg ):
187
185
ser .foo
188
186
189
- def test_datetime_series_no_datelike_attrs (self , datetime_series ):
187
+ @pytest .mark .parametrize ("op" , ["year" , "day" , "second" , "weekday" ])
188
+ def test_datetime_series_no_datelike_attrs (self , op , datetime_series ):
190
189
# GH#7206
191
- for op in ["year" , "day" , "second" , "weekday" ]:
192
- msg = f"'Series' object has no attribute '{ op } '"
193
- with pytest .raises (AttributeError , match = msg ):
194
- getattr (datetime_series , op )
190
+ msg = f"'Series' object has no attribute '{ op } '"
191
+ with pytest .raises (AttributeError , match = msg ):
192
+ getattr (datetime_series , op )
195
193
196
194
def test_series_datetimelike_attribute_access (self ):
197
195
# attribute access should still work!
198
196
ser = Series ({"year" : 2000 , "month" : 1 , "day" : 10 })
199
197
assert ser .year == 2000
200
198
assert ser .month == 1
201
199
assert ser .day == 10
200
+
201
+ def test_series_datetimelike_attribute_access_invalid (self ):
202
+ ser = Series ({"year" : 2000 , "month" : 1 , "day" : 10 })
202
203
msg = "'Series' object has no attribute 'weekday'"
203
204
with pytest .raises (AttributeError , match = msg ):
204
205
ser .weekday
0 commit comments