Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Remove assertNotIn from testing #16096

Merged
merged 2 commits into from
Apr 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,16 @@ def test_rename_nocopy(self):

def test_rename_inplace(self):
self.frame.rename(columns={'C': 'foo'})
self.assertIn('C', self.frame)
self.assertNotIn('foo', self.frame)
assert 'C' in self.frame
assert 'foo' not in self.frame

c_id = id(self.frame['C'])
frame = self.frame.copy()
frame.rename(columns={'C': 'foo'}, inplace=True)

self.assertNotIn('C', frame)
self.assertIn('foo', frame)
self.assertNotEqual(id(frame['foo']), c_id)
assert 'C' not in frame
assert 'foo' in frame
assert id(frame['foo']) != c_id

def test_rename_bug(self):
# GH 5344
Expand Down Expand Up @@ -778,8 +778,9 @@ def test_set_index_names(self):

def test_rename_objects(self):
renamed = self.mixed_frame.rename(columns=str.upper)
self.assertIn('FOO', renamed)
self.assertNotIn('foo', renamed)

assert 'FOO' in renamed
assert 'foo' not in renamed

def test_assign_columns(self):
self.frame['hi'] = 'there'
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def test_corrwith(self):

dropped = a.corrwith(b, axis=0, drop=True)
tm.assert_almost_equal(dropped['A'], a['A'].corr(b['A']))
self.assertNotIn('B', dropped)
assert 'B' not in dropped

dropped = a.corrwith(b, axis=1, drop=True)
self.assertNotIn(a.index[-1], dropped.index)
assert a.index[-1] not in dropped.index

# non time-series data
index = ['a', 'b', 'c', 'd', 'e']
Expand Down
66 changes: 32 additions & 34 deletions pandas/tests/frame/test_axis_select_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
date_range, isnull)
import pandas as pd

from pandas.util.testing import (assert_series_equal,
assert_frame_equal,
assertRaisesRegexp)
from pandas.util.testing import assert_frame_equal

from pandas.errors import PerformanceWarning
import pandas.util.testing as tm
Expand Down Expand Up @@ -287,15 +285,15 @@ def test_reindex_like(self):
assert_frame_equal(other, self.frame.reindex_like(other))

def test_reindex_columns(self):
newFrame = self.frame.reindex(columns=['A', 'B', 'E'])
new_frame = self.frame.reindex(columns=['A', 'B', 'E'])

assert_series_equal(newFrame['B'], self.frame['B'])
self.assertTrue(np.isnan(newFrame['E']).all())
self.assertNotIn('C', newFrame)
tm.assert_series_equal(new_frame['B'], self.frame['B'])
assert np.isnan(new_frame['E']).all()
assert 'C' not in new_frame

# length zero
newFrame = self.frame.reindex(columns=[])
self.assertTrue(newFrame.empty)
# Length zero
new_frame = self.frame.reindex(columns=[])
assert new_frame.empty

def test_reindex_columns_method(self):

Expand Down Expand Up @@ -659,75 +657,75 @@ def test_align_series_combinations(self):
tm.assert_frame_equal(res2, exp1)

def test_filter(self):
# items
# Items
filtered = self.frame.filter(['A', 'B', 'E'])
self.assertEqual(len(filtered.columns), 2)
self.assertNotIn('E', filtered)
assert len(filtered.columns) == 2
assert 'E' not in filtered

filtered = self.frame.filter(['A', 'B', 'E'], axis='columns')
self.assertEqual(len(filtered.columns), 2)
self.assertNotIn('E', filtered)
assert len(filtered.columns) == 2
assert 'E' not in filtered

# other axis
# Other axis
idx = self.frame.index[0:4]
filtered = self.frame.filter(idx, axis='index')
expected = self.frame.reindex(index=idx)
assert_frame_equal(filtered, expected)
tm.assert_frame_equal(filtered, expected)

# like
fcopy = self.frame.copy()
fcopy['AA'] = 1

filtered = fcopy.filter(like='A')
self.assertEqual(len(filtered.columns), 2)
self.assertIn('AA', filtered)
assert len(filtered.columns) == 2
assert 'AA' in filtered

# like with ints in column names
df = DataFrame(0., index=[0, 1, 2], columns=[0, 1, '_A', '_B'])
filtered = df.filter(like='_')
self.assertEqual(len(filtered.columns), 2)
assert len(filtered.columns) == 2

# regex with ints in column names
# from PR #10384
df = DataFrame(0., index=[0, 1, 2], columns=['A1', 1, 'B', 2, 'C'])
expected = DataFrame(
0., index=[0, 1, 2], columns=pd.Index([1, 2], dtype=object))
filtered = df.filter(regex='^[0-9]+$')
assert_frame_equal(filtered, expected)
tm.assert_frame_equal(filtered, expected)

expected = DataFrame(0., index=[0, 1, 2], columns=[0, '0', 1, '1'])
# shouldn't remove anything
filtered = expected.filter(regex='^[0-9]+$')
assert_frame_equal(filtered, expected)
tm.assert_frame_equal(filtered, expected)

# pass in None
with assertRaisesRegexp(TypeError, 'Must pass'):
with tm.assertRaisesRegexp(TypeError, 'Must pass'):
self.frame.filter()
with assertRaisesRegexp(TypeError, 'Must pass'):
with tm.assertRaisesRegexp(TypeError, 'Must pass'):
self.frame.filter(items=None)
with assertRaisesRegexp(TypeError, 'Must pass'):
with tm.assertRaisesRegexp(TypeError, 'Must pass'):
self.frame.filter(axis=1)

# test mutually exclusive arguments
with assertRaisesRegexp(TypeError, 'mutually exclusive'):
with tm.assertRaisesRegexp(TypeError, 'mutually exclusive'):
self.frame.filter(items=['one', 'three'], regex='e$', like='bbi')
with assertRaisesRegexp(TypeError, 'mutually exclusive'):
with tm.assertRaisesRegexp(TypeError, 'mutually exclusive'):
self.frame.filter(items=['one', 'three'], regex='e$', axis=1)
with assertRaisesRegexp(TypeError, 'mutually exclusive'):
with tm.assertRaisesRegexp(TypeError, 'mutually exclusive'):
self.frame.filter(items=['one', 'three'], regex='e$')
with assertRaisesRegexp(TypeError, 'mutually exclusive'):
with tm.assertRaisesRegexp(TypeError, 'mutually exclusive'):
self.frame.filter(items=['one', 'three'], like='bbi', axis=0)
with assertRaisesRegexp(TypeError, 'mutually exclusive'):
with tm.assertRaisesRegexp(TypeError, 'mutually exclusive'):
self.frame.filter(items=['one', 'three'], like='bbi')

# objects
filtered = self.mixed_frame.filter(like='foo')
self.assertIn('foo', filtered)
assert 'foo' in filtered

# unicode columns, won't ascii-encode
df = self.frame.rename(columns={'B': u('\u2202')})
filtered = df.filter(like='C')
self.assertTrue('C' in filtered)
assert 'C' in filtered

def test_filter_regex_search(self):
fcopy = self.frame.copy()
Expand Down Expand Up @@ -857,10 +855,10 @@ def test_reindex_boolean(self):

def test_reindex_objects(self):
reindexed = self.mixed_frame.reindex(columns=['foo', 'A', 'B'])
self.assertIn('foo', reindexed)
assert 'foo' in reindexed

reindexed = self.mixed_frame.reindex(columns=['A', 'B'])
self.assertNotIn('foo', reindexed)
assert 'foo' not in reindexed

def test_reindex_corner(self):
index = Index(['a', 'b', 'c'])
Expand Down
26 changes: 13 additions & 13 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def test_constructor_dict(self):
'col2': self.ts2})

# col2 is padded with NaN
self.assertEqual(len(self.ts1), 30)
self.assertEqual(len(self.ts2), 25)
assert len(self.ts1) == 30
assert len(self.ts2) == 25

tm.assert_series_equal(self.ts1, frame['col1'], check_names=False)

Expand All @@ -223,12 +223,12 @@ def test_constructor_dict(self):
'col2': self.ts2},
columns=['col2', 'col3', 'col4'])

self.assertEqual(len(frame), len(self.ts2))
self.assertNotIn('col1', frame)
self.assertTrue(isnull(frame['col3']).all())
assert len(frame) == len(self.ts2)
assert 'col1' not in frame
assert isnull(frame['col3']).all()

# Corner cases
self.assertEqual(len(DataFrame({})), 0)
assert len(DataFrame({})) == 0

# mix dict and array, wrong size - no spec for which error should raise
# first
Expand All @@ -242,14 +242,14 @@ def test_constructor_dict(self):
# empty dict plus index
idx = Index([0, 1, 2])
frame = DataFrame({}, index=idx)
self.assertIs(frame.index, idx)
assert frame.index is idx

# empty with index and columns
idx = Index([0, 1, 2])
frame = DataFrame({}, index=idx, columns=idx)
self.assertIs(frame.index, idx)
self.assertIs(frame.columns, idx)
self.assertEqual(len(frame._series), 3)
assert frame.index is idx
assert frame.columns is idx
assert len(frame._series) == 3

# with dict of empty list and Series
frame = DataFrame({'A': [], 'B': []}, columns=['A', 'B'])
Expand Down Expand Up @@ -1533,11 +1533,11 @@ def test_from_records_to_records(self):

# what to do?
records = indexed_frame.to_records()
self.assertEqual(len(records.dtype.names), 3)
assert len(records.dtype.names) == 3

records = indexed_frame.to_records(index=False)
self.assertEqual(len(records.dtype.names), 2)
self.assertNotIn('index', records.dtype.names)
assert len(records.dtype.names) == 2
assert 'index' not in records.dtype.names

def test_from_records_nones(self):
tuples = [(1, 2, None, 3),
Expand Down
17 changes: 7 additions & 10 deletions pandas/tests/frame/test_mutate_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

from pandas import DataFrame, Series, Index, MultiIndex

from pandas.util.testing import (assert_series_equal,
assert_frame_equal,
assertRaisesRegexp)
from pandas.util.testing import assert_frame_equal, assertRaisesRegexp

import pandas.util.testing as tm

Expand Down Expand Up @@ -163,7 +161,7 @@ def test_insert(self):

def test_delitem(self):
del self.frame['A']
self.assertNotIn('A', self.frame)
assert 'A' not in self.frame

def test_delitem_multiindex(self):
midx = MultiIndex.from_product([['A', 'B'], [1, 2]])
Expand Down Expand Up @@ -194,15 +192,14 @@ def test_pop(self):
self.frame.columns.name = 'baz'

self.frame.pop('A')
self.assertNotIn('A', self.frame)
assert 'A' not in self.frame

self.frame['foo'] = 'bar'
self.frame.pop('foo')
self.assertNotIn('foo', self.frame)
assert 'foo' not in self.frame
# TODO self.assertEqual(self.frame.columns.name, 'baz')

# 10912
# inplace ops cause caching issue
# gh-10912: inplace ops cause caching issue
a = DataFrame([[1, 2, 3], [4, 5, 6]], columns=[
'A', 'B', 'C'], index=['X', 'Y'])
b = a.pop('B')
Expand All @@ -211,11 +208,11 @@ def test_pop(self):
# original frame
expected = DataFrame([[1, 3], [4, 6]], columns=[
'A', 'C'], index=['X', 'Y'])
assert_frame_equal(a, expected)
tm.assert_frame_equal(a, expected)

# result
expected = Series([2, 5], index=['X', 'Y'], name='B') + 1
assert_series_equal(b, expected)
tm.assert_series_equal(b, expected)

def test_pop_non_unique_cols(self):
df = DataFrame({0: [0, 1], 1: [0, 1], 2: [4, 5]})
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,8 @@ def test_add_string(self):
index = Index(['a', 'b', 'c'])
index2 = index + 'foo'

self.assertNotIn('a', index2)
self.assertIn('afoo', index2)
assert 'a' not in index2
assert 'afoo' in index2

def test_iadd_string(self):
index = pd.Index(['a', 'b', 'c'])
Expand Down
29 changes: 15 additions & 14 deletions pandas/tests/indexes/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,20 +458,20 @@ def test_get_indexer_subintervals(self):
tm.assert_numpy_array_equal(actual, expected)

def test_contains(self):
# only endpoints are valid
# Only endpoints are valid.
i = IntervalIndex.from_arrays([0, 1], [1, 2])

# invalid
self.assertNotIn(0, i)
self.assertNotIn(1, i)
self.assertNotIn(2, i)
# Invalid
assert 0 not in i
assert 1 not in i
assert 2 not in i

# valid
self.assertIn(Interval(0, 1), i)
self.assertIn(Interval(0, 2), i)
self.assertIn(Interval(0, 0.5), i)
self.assertNotIn(Interval(3, 5), i)
self.assertNotIn(Interval(-1, 0, closed='left'), i)
# Valid
assert Interval(0, 1) in i
assert Interval(0, 2) in i
assert Interval(0, 0.5) in i
assert Interval(3, 5) not in i
assert Interval(-1, 0, closed='left') not in i

def testcontains(self):
# can select values that are IN the range of a value
Expand Down Expand Up @@ -509,7 +509,7 @@ def test_non_contiguous(self):
expected = np.array([0, -1, 1], dtype='intp')
tm.assert_numpy_array_equal(actual, expected)

self.assertNotIn(1.5, index)
assert 1.5 not in index

def test_union(self):
other = IntervalIndex.from_arrays([2], [3])
Expand Down Expand Up @@ -651,11 +651,12 @@ def test_datetime(self):
expected = pd.date_range('2000-01-01T12:00', periods=2)
tm.assert_index_equal(idx.mid, expected)

self.assertNotIn(pd.Timestamp('2000-01-01T12'), idx)
self.assertNotIn(pd.Timestamp('2000-01-01T12'), idx)
assert pd.Timestamp('2000-01-01T12') not in idx
assert pd.Timestamp('2000-01-01T12') not in idx

target = pd.date_range('1999-12-31T12:00', periods=7, freq='12H')
actual = idx.get_indexer(target)

expected = np.array([-1, -1, 0, 0, 1, 1, -1], dtype='intp')
tm.assert_numpy_array_equal(actual, expected)

Expand Down
Loading