Skip to content

CLN: Finish changing assert_(...) to specialized forms #6580

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
Mar 9, 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
3 changes: 1 addition & 2 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,7 @@ def test_parse_dates_implicit_first_col(self):
"""
df = self.read_csv(StringIO(data), parse_dates=True)
expected = self.read_csv(StringIO(data), index_col=0, parse_dates=True)
self.assert_(
isinstance(df.index[0], (datetime, np.datetime64, Timestamp)))
self.assertIsInstance(df.index[0], (datetime, np.datetime64, Timestamp))
tm.assert_frame_equal(df, expected)

def test_parse_dates_string(self):
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def test_hexbin_basic(self):

ax = df.plot(kind='hexbin', x='A', y='B', gridsize=10)
# TODO: need better way to test. This just does existence.
self.assert_(len(ax.collections) == 1)
self.assertEqual(len(ax.collections), 1)

@slow
def test_hexbin_with_c(self):
Expand All @@ -973,11 +973,11 @@ def test_hexbin_with_c(self):
"C": np.arange(20) + np.random.uniform(size=20)})

ax = df.plot(kind='hexbin', x='A', y='B', C='C')
self.assert_(len(ax.collections) == 1)
self.assertEqual(len(ax.collections), 1)

ax = df.plot(kind='hexbin', x='A', y='B', C='C',
reduce_C_function=np.std)
self.assert_(len(ax.collections) == 1)
self.assertEqual(len(ax.collections), 1)

@slow
def test_hexbin_cmap(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ def test_reset_index_with_drop(self):

deleveled = self.series.reset_index()
tm.assert_isinstance(deleveled, DataFrame)
self.assert_(
len(deleveled.columns) == len(self.series.index.levels) + 1)
self.assertEqual(len(deleveled.columns),
len(self.series.index.levels) + 1)

deleveled = self.series.reset_index(drop=True)
tm.assert_isinstance(deleveled, Series)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2879,8 +2879,8 @@ def test_fillna(self):

ts[2] = np.NaN

self.assert_(
np.array_equal(ts.fillna(method='ffill'), [0., 1., 1., 3., 4.]))
self.assert_numpy_array_equal(ts.fillna(method='ffill'),
[0., 1., 1., 3., 4.])
self.assert_numpy_array_equal(ts.fillna(method='backfill'),
[0., 1., 3., 3., 4.])

Expand Down
32 changes: 12 additions & 20 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,11 +894,9 @@ def test_to_datetime_types(self):

def test_to_datetime_unprocessable_input(self):
# GH 4928
self.assert_(
np.array_equal(
to_datetime([1, '1']),
np.array([1, '1'], dtype='O')
)
self.assert_numpy_array_equal(
to_datetime([1, '1']),
np.array([1, '1'], dtype='O')
)
self.assertRaises(TypeError, to_datetime, [1, '1'], errors='raise')

Expand Down Expand Up @@ -953,11 +951,9 @@ def test_to_datetime_array_of_dt64s(self):

# Assuming all datetimes are in bounds, to_datetime() returns
# an array that is equal to Timestamp() parsing
self.assert_(
np.array_equal(
pd.to_datetime(dts, box=False),
np.array([Timestamp(x).asm8 for x in dts])
)
self.assert_numpy_array_equal(
pd.to_datetime(dts, box=False),
np.array([Timestamp(x).asm8 for x in dts])
)

# A list of datetimes where the last one is out of bounds
Expand All @@ -971,30 +967,26 @@ def test_to_datetime_array_of_dt64s(self):
errors='raise'
)

self.assert_(
np.array_equal(
pd.to_datetime(dts_with_oob, box=False, coerce=True),
np.array(
self.assert_numpy_array_equal(
pd.to_datetime(dts_with_oob, box=False, coerce=True),
np.array(
[
Timestamp(dts_with_oob[0]).asm8,
Timestamp(dts_with_oob[1]).asm8,
iNaT,
],
dtype='M8'
)
)
)

# With coerce=False and errors='ignore', out of bounds datetime64s
# are converted to their .item(), which depending on the version of
# numpy is either a python datetime.datetime or datetime.date
self.assert_(
np.array_equal(
pd.to_datetime(dts_with_oob, box=False, coerce=False),
np.array(
self.assert_numpy_array_equal(
pd.to_datetime(dts_with_oob, box=False, coerce=False),
np.array(
[dt.item() for dt in dts_with_oob],
dtype='O'
)
)
)

Expand Down
44 changes: 17 additions & 27 deletions pandas/tseries/tests/test_tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,26 @@ def test_does_not_convert_mixed_integer(self):
class TestArrayToDatetime(tm.TestCase):
def test_parsing_valid_dates(self):
arr = np.array(['01-01-2013', '01-02-2013'], dtype=object)
self.assert_(
np.array_equal(
tslib.array_to_datetime(arr),
np.array(
self.assert_numpy_array_equal(
tslib.array_to_datetime(arr),
np.array(
[
'2013-01-01T00:00:00.000000000-0000',
'2013-01-02T00:00:00.000000000-0000'
],
dtype='M8[ns]'
)
)
)

arr = np.array(['Mon Sep 16 2013', 'Tue Sep 17 2013'], dtype=object)
self.assert_(
np.array_equal(
tslib.array_to_datetime(arr),
np.array(
self.assert_numpy_array_equal(
tslib.array_to_datetime(arr),
np.array(
[
'2013-09-16T00:00:00.000000000-0000',
'2013-09-17T00:00:00.000000000-0000'
],
dtype='M8[ns]'
)
)
)

Expand Down Expand Up @@ -155,16 +151,14 @@ def test_coercing_dates_outside_of_datetime64_ns_bounds(self):
)

arr = np.array(['1/1/1000', '1/1/2000'], dtype=object)
self.assert_(
np.array_equal(
tslib.array_to_datetime(arr, coerce=True),
np.array(
self.assert_numpy_array_equal(
tslib.array_to_datetime(arr, coerce=True),
np.array(
[
tslib.iNaT,
'2000-01-01T00:00:00.000000000-0000'
],
dtype='M8[ns]'
)
)
)

Expand All @@ -176,17 +170,15 @@ def test_coerce_of_invalid_datetimes(self):
self.assert_numpy_array_equal(tslib.array_to_datetime(arr), arr)

# With coercing, the invalid dates becomes iNaT
self.assert_(
np.array_equal(
tslib.array_to_datetime(arr, coerce=True),
np.array(
self.assert_numpy_array_equal(
tslib.array_to_datetime(arr, coerce=True),
np.array(
[
'2013-01-01T00:00:00.000000000-0000',
tslib.iNaT,
tslib.iNaT
],
dtype='M8[ns]'
)
)
)

Expand All @@ -205,13 +197,11 @@ def test_parsing_timezone_offsets(self):
)

for dt_string in dt_strings:
self.assert_(
np.array_equal(
tslib.array_to_datetime(
np.array([dt_string], dtype=object)
),
expected_output
)
self.assert_numpy_array_equal(
tslib.array_to_datetime(
np.array([dt_string], dtype=object)
),
expected_output
)

class TestTimestampNsOperations(tm.TestCase):
Expand Down