@@ -18,7 +18,6 @@ class TestABCClasses(object):
18
18
df = pd .DataFrame ({'names' : ['a' , 'b' , 'c' ]}, index = multi_index )
19
19
sparse_series = pd .Series ([1 , 2 , 3 ]).to_sparse ()
20
20
sparse_array = pd .SparseArray (np .random .randn (10 ))
21
- series = pd .Series ([1 , 2 , 3 ])
22
21
23
22
def test_abc_types (self ):
24
23
assert isinstance (pd .Index (['a' , 'b' , 'c' ]), gt .ABCIndex )
@@ -42,31 +41,35 @@ def test_abc_types(self):
42
41
assert isinstance (pd .Period ('2012' , freq = 'A-DEC' ), gt .ABCPeriod )
43
42
44
43
45
- class TestABCWarnings ( object ):
44
+ def test_setattr_warnings ( ):
46
45
# GH5904 - Suggestion: Warning for DataFrame colname-methodname clash
47
46
# GH7175 - GOTCHA: You can't use dot notation to add a column...
48
47
d = {'one' : pd .Series ([1. , 2. , 3. ], index = ['a' , 'b' , 'c' ]),
49
48
'two' : pd .Series ([1. , 2. , 3. , 4. ], index = ['a' , 'b' , 'c' , 'd' ])}
50
49
df = pd .DataFrame (d )
51
50
52
- def test_setattr_warnings (self ):
53
- with catch_warnings (record = True ) as w :
54
- # successfully add new column
55
- self .df ['three' ] = self .df .two + 1
56
- assert len (w ) == 0
57
- assert self .df .three .sum () > self .df .two .sum ()
58
- with catch_warnings (record = True ) as w :
59
- # successfully modify column in place
60
- self .df .one += 1
61
- assert len (w ) == 0
62
- assert self .df .one .iloc [0 ] == 2
63
- with catch_warnings (record = True ) as w :
64
- # successfully add an attribute to a series
65
- self .df .two .not_an_index = [1 , 2 ]
66
- assert len (w ) == 0
67
- with tm .assert_produces_warning (UserWarning ):
68
- # warn when setting column to nonexistent name
69
- self .df .four = self .df .two + 2
70
- with tm .assert_produces_warning (UserWarning ):
71
- # warn when column has same name as method
72
- self .df ['sum' ] = self .df .two
51
+ with catch_warnings (record = True ) as w :
52
+ # successfully add new column
53
+ df ['three' ] = df .two + 1
54
+ assert len (w ) == 0
55
+ assert df .three .sum () > df .two .sum ()
56
+
57
+ with catch_warnings (record = True ) as w :
58
+ # successfully modify column in place
59
+ df .one += 1
60
+ assert len (w ) == 0
61
+ assert df .one .iloc [0 ] == 2
62
+
63
+ with catch_warnings (record = True ) as w :
64
+ # successfully add an attribute to a series
65
+ df .two .not_an_index = [1 , 2 ]
66
+ assert len (w ) == 0
67
+
68
+ with tm .assert_produces_warning (UserWarning ):
69
+ # warn when setting column to nonexistent name
70
+ df .four = df .two + 2
71
+ assert df .four .sum () > df .two .sum ()
72
+
73
+ with tm .assert_produces_warning (UserWarning ):
74
+ # warn when column has same name as method
75
+ df ['sum' ] = df .two
0 commit comments