Skip to content

Commit 6bcb426

Browse files
committed
CLN: reformatting and cleanup of setting tests
1 parent c04b874 commit 6bcb426

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

pandas/tests/dtypes/test_generic.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class TestABCClasses(object):
1818
df = pd.DataFrame({'names': ['a', 'b', 'c']}, index=multi_index)
1919
sparse_series = pd.Series([1, 2, 3]).to_sparse()
2020
sparse_array = pd.SparseArray(np.random.randn(10))
21-
series = pd.Series([1, 2, 3])
2221

2322
def test_abc_types(self):
2423
assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndex)
@@ -42,31 +41,35 @@ def test_abc_types(self):
4241
assert isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCPeriod)
4342

4443

45-
class TestABCWarnings(object):
44+
def test_setattr_warnings():
4645
# GH5904 - Suggestion: Warning for DataFrame colname-methodname clash
4746
# GH7175 - GOTCHA: You can't use dot notation to add a column...
4847
d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
4948
'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
5049
df = pd.DataFrame(d)
5150

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

Comments
 (0)