Skip to content

CLN: Work on converting assert_'s to specialized forms, in pandas/tests #6262

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 5, 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
76 changes: 38 additions & 38 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_hash_error(self):

def test_new_axis(self):
new_index = self.dateIndex[None, :]
self.assert_(new_index.ndim == 2)
self.assertEqual(new_index.ndim, 2)
tm.assert_isinstance(new_index, np.ndarray)

def test_copy_and_deepcopy(self):
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_constructor(self):
arr = np.array(self.strIndex)
index = Index(arr, copy=True, name='name')
tm.assert_isinstance(index, Index)
self.assert_(index.name == 'name')
self.assertEqual(index.name, 'name')
assert_array_equal(arr, index)
arr[0] = "SOMEBIGLONGSTRING"
self.assertNotEqual(index[0], "SOMEBIGLONGSTRING")
Expand All @@ -156,12 +156,12 @@ def test_index_ctor_infer_periodindex(self):
def test_copy(self):
i = Index([], name='Foo')
i_copy = i.copy()
self.assert_(i_copy.name == 'Foo')
self.assertEqual(i_copy.name, 'Foo')

def test_view(self):
i = Index([], name='Foo')
i_view = i.view()
self.assert_(i_view.name == 'Foo')
self.assertEqual(i_view.name, 'Foo')

def test_astype(self):
casted = self.intIndex.astype('i8')
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_asof(self):
self.assert_(np.isnan(self.dateIndex.asof(d - timedelta(1))))

d = self.dateIndex[-1]
self.assert_(self.dateIndex.asof(d + timedelta(1)) == d)
self.assertEqual(self.dateIndex.asof(d + timedelta(1)), d)

d = self.dateIndex[0].to_datetime()
tm.assert_isinstance(self.dateIndex.asof(d), Timestamp)
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_union(self):
first.name = 'A'
second.name = 'A'
union = first.union(second)
self.assert_(union.name == 'A')
self.assertEqual(union.name, 'A')

second.name = 'B'
union = first.union(second)
Expand Down Expand Up @@ -393,7 +393,7 @@ def test_append_empty_preserve_name(self):
right = Index([1, 2, 3], name='foo')

result = left.append(right)
self.assert_(result.name == 'foo')
self.assertEqual(result.name, 'foo')

left = Index([], name='foo')
right = Index([1, 2, 3], name='bar')
Expand Down Expand Up @@ -440,7 +440,7 @@ def test_diff(self):

# with everythin
result = first.diff(first)
self.assert_(len(result) == 0)
self.assertEqual(len(result), 0)
self.assertEqual(result.name, first.name)

# non-iterable input
Expand Down Expand Up @@ -511,14 +511,14 @@ def test_format_with_name_time_info(self):
dates = Index([dt + inc for dt in self.dateIndex], name='something')

formatted = dates.format(name=True)
self.assert_(formatted[0] == 'something')
self.assertEqual(formatted[0], 'something')

def test_format_datetime_with_time(self):
t = Index([datetime(2012, 2, 7), datetime(2012, 2, 7, 23)])

result = t.format()
expected = ['2012-02-07 00:00:00', '2012-02-07 23:00:00']
self.assert_(len(result) == 2)
self.assertEqual(len(result), 2)
self.assertEquals(result, expected)

def test_format_none(self):
Expand Down Expand Up @@ -579,16 +579,16 @@ def test_slice_locs(self):
def test_slice_locs_dup(self):
idx = Index(['a', 'a', 'b', 'c', 'd', 'd'])
rs = idx.slice_locs('a', 'd')
self.assert_(rs == (0, 6))
self.assertEqual(rs, (0, 6))

rs = idx.slice_locs(end='d')
self.assert_(rs == (0, 6))
self.assertEqual(rs, (0, 6))

rs = idx.slice_locs('a', 'c')
self.assert_(rs == (0, 4))
self.assertEqual(rs, (0, 4))

rs = idx.slice_locs('b', 'd')
self.assert_(rs == (2, 6))
self.assertEqual(rs, (2, 6))

def test_drop(self):
n = len(self.strIndex)
Expand Down Expand Up @@ -624,13 +624,13 @@ def test_tuple_union_bug(self):
int_idx = idx1.intersection(idx2)
# needs to be 1d like idx1 and idx2
expected = idx1[:4] # pandas.Index(sorted(set(idx1) & set(idx2)))
self.assert_(int_idx.ndim == 1)
self.assertEqual(int_idx.ndim, 1)
self.assert_(int_idx.equals(expected))

# union broken
union_idx = idx1.union(idx2)
expected = pandas.Index(sorted(set(idx1) | set(idx2)))
self.assert_(union_idx.ndim == 1)
self.assertEqual(union_idx.ndim, 1)
self.assert_(union_idx.equals(expected))

def test_is_monotonic_incomparable(self):
Expand Down Expand Up @@ -658,8 +658,8 @@ def test_isin(self):
# empty, return dtype bool
idx = Index([])
result = idx.isin(values)
self.assert_(len(result) == 0)
self.assert_(result.dtype == np.bool_)
self.assertEqual(len(result), 0)
self.assertEqual(result.dtype, np.bool_)

def test_boolean_cmp(self):
values = [1, 2, 3, 4]
Expand All @@ -668,7 +668,7 @@ def test_boolean_cmp(self):
res = (idx == values)

self.assert_(res.all())
self.assert_(res.dtype == 'bool')
self.assertEqual(res.dtype, 'bool')
self.assert_(not isinstance(res, Index))

def test_get_level_values(self):
Expand Down Expand Up @@ -728,15 +728,15 @@ def test_constructor(self):
self.assert_(isinstance(index, Float64Index))
index = Float64Index(np.array([1.,2,3,4,5]))
self.assert_(isinstance(index, Float64Index))
self.assert_(index.dtype == object)
self.assertEqual(index.dtype, object)

index = Float64Index(np.array([1.,2,3,4,5]),dtype=np.float32)
self.assert_(isinstance(index, Float64Index))
self.assert_(index.dtype == object)
self.assertEqual(index.dtype, object)

index = Float64Index(np.array([1,2,3,4,5]),dtype=np.float32)
self.assert_(isinstance(index, Float64Index))
self.assert_(index.dtype == object)
self.assertEqual(index.dtype, object)

# nan handling
result = Float64Index([np.nan, np.nan])
Expand Down Expand Up @@ -818,7 +818,7 @@ def test_constructor(self):
def test_constructor_corner(self):
arr = np.array([1, 2, 3, 4], dtype=object)
index = Int64Index(arr)
self.assert_(index.values.dtype == np.int64)
self.assertEqual(index.values.dtype, np.int64)
self.assert_(index.equals(arr))

# preventing casting
Expand All @@ -839,12 +839,12 @@ def test_hash_error(self):
def test_copy(self):
i = Int64Index([], name='Foo')
i_copy = i.copy()
self.assert_(i_copy.name == 'Foo')
self.assertEqual(i_copy.name, 'Foo')

def test_view(self):
i = Int64Index([], name='Foo')
i_view = i.view()
self.assert_(i_view.name == 'Foo')
self.assertEqual(i_view.name, 'Foo')

def test_coerce_list(self):
# coerce things
Expand All @@ -856,7 +856,7 @@ def test_coerce_list(self):
tm.assert_isinstance(arr, Index)

def test_dtype(self):
self.assert_(self.index.dtype == np.int64)
self.assertEqual(self.index.dtype, np.int64)

def test_is_monotonic(self):
self.assert_(self.index.is_monotonic)
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def test_intersect_str_dates(self):
i2 = Index(['aa'], dtype=object)
res = i2.intersection(i1)

self.assert_(len(res) == 0)
self.assertEqual(len(res), 0)

def test_union_noncomparable(self):
from datetime import datetime, timedelta
Expand Down Expand Up @@ -1152,7 +1152,7 @@ def test_view_Index(self):

def test_prevent_casting(self):
result = self.index.astype('O')
self.assert_(result.dtype == np.object_)
self.assertEqual(result.dtype, np.object_)

def test_take_preserve_name(self):
index = Int64Index([1, 2, 3, 4], name='foo')
Expand Down Expand Up @@ -1223,7 +1223,7 @@ def test_hash_error(self):

def test_set_names_and_rename(self):
# so long as these are synonyms, we don't need to test set_names
self.assert_(self.index.rename == self.index.set_names)
self.assertEqual(self.index.rename, self.index.set_names)
new_names = [name + "SUFFIX" for name in self.index_names]
ind = self.index.set_names(new_names)
self.assertEqual(self.index.names, self.index_names)
Expand Down Expand Up @@ -1433,7 +1433,7 @@ def test_constructor_single_level(self):
names=['first'])
tm.assert_isinstance(single_level, Index)
self.assert_(not isinstance(single_level, MultiIndex))
self.assert_(single_level.name == 'first')
self.assertEqual(single_level.name, 'first')

single_level = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux']],
labels=[[0, 1, 2, 3]])
Expand Down Expand Up @@ -1644,7 +1644,7 @@ def test_iter(self):
result = list(self.index)
expected = [('foo', 'one'), ('foo', 'two'), ('bar', 'one'),
('baz', 'two'), ('qux', 'one'), ('qux', 'two')]
self.assert_(result == expected)
self.assertEqual(result, expected)

def test_pickle(self):
pickled = pickle.dumps(self.index)
Expand Down Expand Up @@ -1735,8 +1735,8 @@ def test_getitem_group_select(self):
self.assertEquals(sorted_idx.get_loc('foo'), slice(0, 2))

def test_get_loc(self):
self.assert_(self.index.get_loc(('foo', 'two')) == 1)
self.assert_(self.index.get_loc(('baz', 'two')) == 3)
self.assertEqual(self.index.get_loc(('foo', 'two')), 1)
self.assertEqual(self.index.get_loc(('baz', 'two')), 3)
self.assertRaises(KeyError, self.index.get_loc, ('bar', 'two'))
self.assertRaises(KeyError, self.index.get_loc, 'quux')

Expand All @@ -1748,13 +1748,13 @@ def test_get_loc(self):
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
np.array([1, 0, 1, 1, 0, 0, 1, 0])])
self.assertRaises(KeyError, index.get_loc, (1, 1))
self.assert_(index.get_loc((2, 0)) == slice(3, 5))
self.assertEqual(index.get_loc((2, 0)), slice(3, 5))

def test_get_loc_duplicates(self):
index = Index([2, 2, 2, 2])
result = index.get_loc(2)
expected = slice(0, 4)
assert(result == expected)
self.assertEqual(result, expected)
# self.assertRaises(Exception, index.get_loc, 2)

index = Index(['c', 'a', 'a', 'b', 'b'])
Expand Down Expand Up @@ -2213,7 +2213,7 @@ def test_diff(self):

# empty, but non-equal
result = self.index - self.index.sortlevel(1)[0]
self.assert_(len(result) == 0)
self.assertEqual(len(result), 0)

# raise Exception called with non-MultiIndex
result = first.diff(first._tuple_index)
Expand Down Expand Up @@ -2352,15 +2352,15 @@ def test_insert(self):
# key contained in all levels
new_index = self.index.insert(0, ('bar', 'two'))
self.assert_(new_index.equal_levels(self.index))
self.assert_(new_index[0] == ('bar', 'two'))
self.assertEqual(new_index[0], ('bar', 'two'))

# key not contained in all levels
new_index = self.index.insert(0, ('abc', 'three'))
self.assert_(np.array_equal(new_index.levels[0],
list(self.index.levels[0]) + ['abc']))
self.assert_(np.array_equal(new_index.levels[1],
list(self.index.levels[1]) + ['three']))
self.assert_(new_index[0] == ('abc', 'three'))
self.assertEqual(new_index[0], ('abc', 'three'))

# key wrong length
assertRaisesRegexp(ValueError, "Item must have length equal to number"
Expand Down
Loading