11
11
Index ,
12
12
MultiIndex ,
13
13
Series ,
14
- isna ,
15
14
)
16
15
import pandas ._testing as tm
17
16
@@ -34,74 +33,6 @@ def assert_series_or_index_equal(left, right):
34
33
tm .assert_index_equal (left , right )
35
34
36
35
37
- def test_iter ():
38
- # GH3638
39
- strs = "google" , "wikimedia" , "wikipedia" , "wikitravel"
40
- ser = Series (strs )
41
-
42
- with tm .assert_produces_warning (FutureWarning ):
43
- for s in ser .str :
44
- # iter must yield a Series
45
- assert isinstance (s , Series )
46
-
47
- # indices of each yielded Series should be equal to the index of
48
- # the original Series
49
- tm .assert_index_equal (s .index , ser .index )
50
-
51
- for el in s :
52
- # each element of the series is either a basestring/str or nan
53
- assert isinstance (el , str ) or isna (el )
54
-
55
- # desired behavior is to iterate until everything would be nan on the
56
- # next iter so make sure the last element of the iterator was 'l' in
57
- # this case since 'wikitravel' is the longest string
58
- assert s .dropna ().values .item () == "l"
59
-
60
-
61
- def test_iter_empty (any_string_dtype ):
62
- ser = Series ([], dtype = any_string_dtype )
63
-
64
- i , s = 100 , 1
65
-
66
- with tm .assert_produces_warning (FutureWarning ):
67
- for i , s in enumerate (ser .str ):
68
- pass
69
-
70
- # nothing to iterate over so nothing defined values should remain
71
- # unchanged
72
- assert i == 100
73
- assert s == 1
74
-
75
-
76
- def test_iter_single_element (any_string_dtype ):
77
- ser = Series (["a" ], dtype = any_string_dtype )
78
-
79
- with tm .assert_produces_warning (FutureWarning ):
80
- for i , s in enumerate (ser .str ):
81
- pass
82
-
83
- assert not i
84
- tm .assert_series_equal (ser , s )
85
-
86
-
87
- def test_iter_object_try_string ():
88
- ser = Series (
89
- [
90
- slice (None , np .random .randint (10 ), np .random .randint (10 , 20 ))
91
- for _ in range (4 )
92
- ]
93
- )
94
-
95
- i , s = 100 , "h"
96
-
97
- with tm .assert_produces_warning (FutureWarning ):
98
- for i , s in enumerate (ser .str ):
99
- pass
100
-
101
- assert i == 100
102
- assert s == "h"
103
-
104
-
105
36
# test integer/float dtypes (inferred by constructor) and mixed
106
37
107
38
0 commit comments