Skip to content

CLN: Change assert_(a is [not] b) to specialized forms #6392

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

Merged
merged 1 commit into from
Feb 18, 2014
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
2 changes: 1 addition & 1 deletion pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ def test_parse_tz_aware(self):
stamp = result.index[0]
self.assertEqual(stamp.minute, 39)
try:
self.assert_(result.index.tz is pytz.utc)
self.assertIs(result.index.tz, pytz.utc)
except AssertionError: # hello Yaroslav
arr = result.index.to_pydatetime()
result = tools.to_datetime(arr, utc=True)[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def test_open_args(self):
if LooseVersion(tables.__version__) >= '3.0.0':

# the file should not have actually been written
self.assert_(os.path.exists(path) is False)
self.assertFalse(os.path.exists(path))

def test_flush(self):

Expand Down
4 changes: 2 additions & 2 deletions pandas/sparse/tests/test_libsparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_to_int_index(self):

def test_to_block_index(self):
index = BlockIndex(10, [0, 5], [4, 5])
self.assert_(index.to_block_index() is index)
self.assertIs(index.to_block_index(), index)


class TestIntIndex(tm.TestCase):
Expand All @@ -294,7 +294,7 @@ def _check_case(xloc, xlen, yloc, ylen, eloc, elen):

def test_to_int_index(self):
index = IntIndex(10, [2, 3, 4, 5, 6])
self.assert_(index.to_int_index() is index)
self.assertIs(index.to_int_index(), index)


class TestSparseOperators(tm.TestCase):
Expand Down
20 changes: 10 additions & 10 deletions pandas/sparse/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def test_constructor_nonnan(self):

def test_copy_astype(self):
cop = self.bseries.astype(np.float64)
self.assert_(cop is not self.bseries)
self.assert_(cop.sp_index is self.bseries.sp_index)
self.assertIsNot(cop, self.bseries)
self.assertIs(cop.sp_index, self.bseries.sp_index)
self.assertEqual(cop.dtype, np.float64)

cop2 = self.iseries.copy()
Expand Down Expand Up @@ -524,7 +524,7 @@ def _compare_with_series(sps, new_index):
# special cases
same_index = self.bseries.reindex(self.bseries.index)
assert_sp_series_equal(self.bseries, same_index)
self.assert_(same_index is not self.bseries)
self.assertIsNot(same_index, self.bseries)

# corner cases
sp = SparseSeries([], index=[])
Expand All @@ -547,7 +547,7 @@ def _check(values, index1, index2, fill_value):
first_series = SparseSeries(values, sparse_index=index1,
fill_value=fill_value)
reindexed = first_series.sparse_reindex(index2)
self.assert_(reindexed.sp_index is index2)
self.assertIs(reindexed.sp_index, index2)

int_indices1 = index1.to_int_index().indices
int_indices2 = index2.to_int_index().indices
Expand Down Expand Up @@ -699,7 +699,7 @@ def test_shift(self):
index=np.arange(6))

shifted = series.shift(0)
self.assert_(shifted is not series)
self.assertIsNot(shifted, series)
assert_sp_series_equal(shifted, series)

f = lambda s: s.shift(1)
Expand Down Expand Up @@ -1093,12 +1093,12 @@ def test_set_value(self):
res.index = res.index.astype(object)

res = self.frame.set_value('foobar', 'B', 1.5)
self.assert_(res is not self.frame)
self.assertIsNot(res, self.frame)
self.assertEqual(res.index[-1], 'foobar')
self.assertEqual(res.get_value('foobar', 'B'), 1.5)

res2 = res.set_value('foobar', 'qux', 1.5)
self.assert_(res2 is not res)
self.assertIsNot(res2, res)
self.assert_numpy_array_equal(res2.columns,
list(self.frame.columns) + ['qux'])
self.assertEqual(res2.get_value('foobar', 'qux'), 1.5)
Expand Down Expand Up @@ -1247,7 +1247,7 @@ def test_apply(self):
assert_frame_equal(broadcasted.to_dense(),
self.frame.to_dense().apply(np.sum, broadcast=True))

self.assert_(self.empty.apply(np.sqrt) is self.empty)
self.assertIs(self.empty.apply(np.sqrt), self.empty)

from pandas.core import nanops
applied = self.frame.apply(np.sum)
Expand Down Expand Up @@ -1656,7 +1656,7 @@ def test_setitem(self):
def test_set_value(self):
def _check_loc(item, major, minor, val=1.5):
res = self.panel.set_value(item, major, minor, val)
self.assert_(res is not self.panel)
self.assertIsNot(res, self.panel)
self.assertEquals(res.get_value(item, major, minor), val)

_check_loc('ItemA', self.panel.major_axis[4], self.panel.minor_axis[3])
Expand All @@ -1669,7 +1669,7 @@ def test_delitem_pop(self):
assert_almost_equal(self.panel.items, ['ItemA', 'ItemC', 'ItemD'])
crackle = self.panel['ItemC']
pop = self.panel.pop('ItemC')
self.assert_(pop is crackle)
self.assertIs(pop, crackle)
assert_almost_equal(self.panel.items, ['ItemA', 'ItemD'])

self.assertRaises(KeyError, self.panel.__delitem__, 'ItemC')
Expand Down
52 changes: 26 additions & 26 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def test_setitem_clear_caches(self):
df.ix[2:, 'z'] = 42

expected = Series([np.nan, np.nan, 42, 42], index=df.index)
self.assert_(df['z'] is not foo)
self.assertIsNot(df['z'], foo)
assert_series_equal(df['z'], expected)

def test_setitem_None(self):
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def test_getitem_fancy_1d(self):
ix = f.ix

# return self if no slicing...for now
self.assert_(ix[:, :] is f)
self.assertIs(ix[:, :], f)

# low dimensional slice
xs1 = ix[2, ['C', 'B', 'A']]
Expand Down Expand Up @@ -1532,7 +1532,7 @@ def test_set_value(self):
def test_set_value_resize(self):

res = self.frame.set_value('foobar', 'B', 0)
self.assert_(res is self.frame)
self.assertIs(res, self.frame)
self.assertEqual(res.index[-1], 'foobar')
self.assertEqual(res.get_value('foobar', 'B'), 0)

Expand Down Expand Up @@ -1943,8 +1943,8 @@ def test_get_axis(self):
self.assertEquals(f._get_axis_name('rows'), 'index')
self.assertEquals(f._get_axis_name('columns'), 'columns')

self.assert_(f._get_axis(0) is f.index)
self.assert_(f._get_axis(1) is f.columns)
self.assertIs(f._get_axis(0), f.index)
self.assertIs(f._get_axis(1), f.columns)

assertRaisesRegexp(ValueError, 'No axis named', f._get_axis_number, 2)
assertRaisesRegexp(ValueError, 'No axis.*foo', f._get_axis_name, 'foo')
Expand All @@ -1957,7 +1957,7 @@ def test_set_index(self):
# cache it
_ = self.mixed_frame['foo']
self.mixed_frame.index = idx
self.assert_(self.mixed_frame['foo'].index is idx)
self.assertIs(self.mixed_frame['foo'].index, idx)
with assertRaisesRegexp(ValueError, 'Length mismatch'):
self.mixed_frame.index = idx[::2]

Expand Down Expand Up @@ -2122,7 +2122,7 @@ def test_set_columns(self):

def test_keys(self):
getkeys = self.frame.keys
self.assert_(getkeys() is self.frame.columns)
self.assertIs(getkeys(), self.frame.columns)

def test_column_contains_typeerror(self):
try:
Expand Down Expand Up @@ -2305,13 +2305,13 @@ def test_constructor_dict(self):
# empty dict plus index
idx = Index([0, 1, 2])
frame = DataFrame({}, index=idx)
self.assert_(frame.index is idx)
self.assertIs(frame.index, idx)

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

# with dict of empty list and Series
Expand Down Expand Up @@ -3717,8 +3717,8 @@ def test_astype_cast_nan_int(self):
def test_array_interface(self):
result = np.sqrt(self.frame)
tm.assert_isinstance(result, type(self.frame))
self.assert_(result.index is self.frame.index)
self.assert_(result.columns is self.frame.columns)
self.assertIs(result.index, self.frame.index)
self.assertIs(result.columns, self.frame.columns)

assert_frame_equal(result, self.frame.apply(np.sqrt))

Expand Down Expand Up @@ -4191,10 +4191,10 @@ def test_from_records_len0_with_columns(self):

def test_get_agg_axis(self):
cols = self.frame._get_agg_axis(0)
self.assert_(cols is self.frame.columns)
self.assertIs(cols, self.frame.columns)

idx = self.frame._get_agg_axis(1)
self.assert_(idx is self.frame.index)
self.assertIs(idx, self.frame.index)

self.assertRaises(ValueError, self.frame._get_agg_axis, 2)

Expand Down Expand Up @@ -4731,7 +4731,7 @@ def test_constructor_lists_to_object_dtype(self):
# from #1074
d = DataFrame({'a': [np.nan, False]})
self.assertEqual(d['a'].dtype, np.object_)
self.assert_(d['a'][1] is False)
self.assertFalse(d['a'][1])

def test_constructor_with_nas(self):
# GH 5016
Expand Down Expand Up @@ -5243,7 +5243,7 @@ def test_combineFunc(self):
_check_mixed_float(result, dtype = dict(C = None))

result = self.empty * 2
self.assert_(result.index is self.empty.index)
self.assertIs(result.index, self.empty.index)
self.assertEqual(len(result.columns), 0)

def test_comparisons(self):
Expand Down Expand Up @@ -6373,7 +6373,7 @@ def test_asfreq(self):
# test does not blow up on length-0 DataFrame
zero_length = self.tsframe.reindex([])
result = zero_length.asfreq('BM')
self.assert_(result is not zero_length)
self.assertIsNot(result, zero_length)

def test_asfreq_datetimeindex(self):
df = DataFrame({'A': [1, 2, 3]},
Expand Down Expand Up @@ -6494,7 +6494,7 @@ def test_copy(self):

# copy objects
copy = self.mixed_frame.copy()
self.assert_(copy._data is not self.mixed_frame._data)
self.assertIsNot(copy._data, self.mixed_frame._data)

def _check_method(self, method='pearson', check_minp=False):
if not check_minp:
Expand Down Expand Up @@ -7134,15 +7134,15 @@ def test_fillna_inplace(self):
df[3][-4:] = np.nan

expected = df.fillna(value=0)
self.assert_(expected is not df)
self.assertIsNot(expected, df)

df.fillna(value=0, inplace=True)
assert_frame_equal(df, expected)

df[1][:4] = np.nan
df[3][-4:] = np.nan
expected = df.fillna(method='ffill')
self.assert_(expected is not df)
self.assertIsNot(expected, df)

df.fillna(method='ffill', inplace=True)
assert_frame_equal(df, expected)
Expand Down Expand Up @@ -8283,7 +8283,7 @@ def test_reindex(self):

# Same index, copies values but not index if copy=False
newFrame = self.frame.reindex(self.frame.index, copy=False)
self.assert_(newFrame.index is self.frame.index)
self.assertIs(newFrame.index, self.frame.index)

# length zero
newFrame = self.frame.reindex([])
Expand Down Expand Up @@ -8424,10 +8424,10 @@ def test_reindex_dups(self):
def test_align(self):

af, bf = self.frame.align(self.frame)
self.assert_(af._data is not self.frame._data)
self.assertIsNot(af._data, self.frame._data)

af, bf = self.frame.align(self.frame, copy=False)
self.assert_(af._data is self.frame._data)
self.assertIs(af._data, self.frame._data)

# axis = 0
other = self.frame.ix[:-5, :3]
Expand Down Expand Up @@ -9106,7 +9106,7 @@ def test_apply(self):
d = self.frame.index[0]
applied = self.frame.apply(np.mean, axis=1)
self.assertEqual(applied[d], np.mean(self.frame.xs(d)))
self.assert_(applied.index is self.frame.index) # want this
self.assertIs(applied.index, self.frame.index) # want this

# invalid axis
df = DataFrame(
Expand Down Expand Up @@ -9232,7 +9232,7 @@ def _checkit(axis=0, raw=False):
if is_reduction:
agg_axis = df._get_agg_axis(axis)
tm.assert_isinstance(res, Series)
self.assert_(res.index is agg_axis)
self.assertIs(res.index, agg_axis)
else:
tm.assert_isinstance(res, DataFrame)

Expand Down Expand Up @@ -11445,7 +11445,7 @@ def test_consolidate(self):

# Ensure copy, do I want this?
recons = consolidated.consolidate()
self.assert_(recons is not consolidated)
self.assertIsNot(recons, consolidated)
assert_frame_equal(recons, consolidated)

self.frame['F'] = 8.
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ def test_nonzero_single_element(self):

# allow single item via bool method
s = Series([True])
self.assert_(s.bool() is True)
self.assertTrue(s.bool())

s = Series([False])
self.assert_(s.bool() is False)
self.assertFalse(s.bool())

# single item nan to raise
for s in [ Series([np.nan]), Series([pd.NaT]), Series([True]), Series([False]) ]:
Expand Down Expand Up @@ -633,10 +633,10 @@ def test_nonzero_single_element(self):

# allow single item via bool method
df = DataFrame([[True]])
self.assert_(df.bool() is True)
self.assertTrue(df.bool())

df = DataFrame([[False]])
self.assert_(df.bool() is False)
self.assertFalse(df.bool())

df = DataFrame([[False, False]])
self.assertRaises(ValueError, lambda : df.bool())
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,14 @@ def test_len(self):
def test_groups(self):
grouped = self.df.groupby(['A'])
groups = grouped.groups
self.assert_(groups is grouped.groups) # caching works
self.assertIs(groups, grouped.groups) # caching works

for k, v in compat.iteritems(grouped.groups):
self.assert_((self.df.ix[v]['A'] == k).all())

grouped = self.df.groupby(['A', 'B'])
groups = grouped.groups
self.assert_(groups is grouped.groups) # caching works
self.assertIs(groups, grouped.groups) # caching works
for k, v in compat.iteritems(grouped.groups):
self.assert_((self.df.ix[v]['A'] == k[0]).all())
self.assert_((self.df.ix[v]['B'] == k[1]).all())
Expand Down
Loading