Skip to content

Commit 48a6849

Browse files
committed
Merge pull request #6580 from bwignall/assert_6175_cleanup
CLN: Finish changing assert_(...) to specialized forms
2 parents 8a573af + 6b891e6 commit 48a6849

File tree

6 files changed

+37
-56
lines changed

6 files changed

+37
-56
lines changed

pandas/io/tests/test_parsers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,7 @@ def test_parse_dates_implicit_first_col(self):
873873
"""
874874
df = self.read_csv(StringIO(data), parse_dates=True)
875875
expected = self.read_csv(StringIO(data), index_col=0, parse_dates=True)
876-
self.assert_(
877-
isinstance(df.index[0], (datetime, np.datetime64, Timestamp)))
876+
self.assertIsInstance(df.index[0], (datetime, np.datetime64, Timestamp))
878877
tm.assert_frame_equal(df, expected)
879878

880879
def test_parse_dates_string(self):

pandas/tests/test_graphics.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def test_hexbin_basic(self):
964964

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

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

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

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

982982
@slow
983983
def test_hexbin_cmap(self):

pandas/tests/test_multilevel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ def test_reset_index_with_drop(self):
695695

696696
deleveled = self.series.reset_index()
697697
tm.assert_isinstance(deleveled, DataFrame)
698-
self.assert_(
699-
len(deleveled.columns) == len(self.series.index.levels) + 1)
698+
self.assertEqual(len(deleveled.columns),
699+
len(self.series.index.levels) + 1)
700700

701701
deleveled = self.series.reset_index(drop=True)
702702
tm.assert_isinstance(deleveled, Series)

pandas/tests/test_series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2879,8 +2879,8 @@ def test_fillna(self):
28792879

28802880
ts[2] = np.NaN
28812881

2882-
self.assert_(
2883-
np.array_equal(ts.fillna(method='ffill'), [0., 1., 1., 3., 4.]))
2882+
self.assert_numpy_array_equal(ts.fillna(method='ffill'),
2883+
[0., 1., 1., 3., 4.])
28842884
self.assert_numpy_array_equal(ts.fillna(method='backfill'),
28852885
[0., 1., 3., 3., 4.])
28862886

pandas/tseries/tests/test_timeseries.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -894,11 +894,9 @@ def test_to_datetime_types(self):
894894

895895
def test_to_datetime_unprocessable_input(self):
896896
# GH 4928
897-
self.assert_(
898-
np.array_equal(
899-
to_datetime([1, '1']),
900-
np.array([1, '1'], dtype='O')
901-
)
897+
self.assert_numpy_array_equal(
898+
to_datetime([1, '1']),
899+
np.array([1, '1'], dtype='O')
902900
)
903901
self.assertRaises(TypeError, to_datetime, [1, '1'], errors='raise')
904902

@@ -953,11 +951,9 @@ def test_to_datetime_array_of_dt64s(self):
953951

954952
# Assuming all datetimes are in bounds, to_datetime() returns
955953
# an array that is equal to Timestamp() parsing
956-
self.assert_(
957-
np.array_equal(
958-
pd.to_datetime(dts, box=False),
959-
np.array([Timestamp(x).asm8 for x in dts])
960-
)
954+
self.assert_numpy_array_equal(
955+
pd.to_datetime(dts, box=False),
956+
np.array([Timestamp(x).asm8 for x in dts])
961957
)
962958

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

974-
self.assert_(
975-
np.array_equal(
976-
pd.to_datetime(dts_with_oob, box=False, coerce=True),
977-
np.array(
970+
self.assert_numpy_array_equal(
971+
pd.to_datetime(dts_with_oob, box=False, coerce=True),
972+
np.array(
978973
[
979974
Timestamp(dts_with_oob[0]).asm8,
980975
Timestamp(dts_with_oob[1]).asm8,
981976
iNaT,
982977
],
983978
dtype='M8'
984-
)
985979
)
986980
)
987981

988982
# With coerce=False and errors='ignore', out of bounds datetime64s
989983
# are converted to their .item(), which depending on the version of
990984
# numpy is either a python datetime.datetime or datetime.date
991-
self.assert_(
992-
np.array_equal(
993-
pd.to_datetime(dts_with_oob, box=False, coerce=False),
994-
np.array(
985+
self.assert_numpy_array_equal(
986+
pd.to_datetime(dts_with_oob, box=False, coerce=False),
987+
np.array(
995988
[dt.item() for dt in dts_with_oob],
996989
dtype='O'
997-
)
998990
)
999991
)
1000992

pandas/tseries/tests/test_tslib.py

+17-27
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,26 @@ def test_does_not_convert_mixed_integer(self):
9191
class TestArrayToDatetime(tm.TestCase):
9292
def test_parsing_valid_dates(self):
9393
arr = np.array(['01-01-2013', '01-02-2013'], dtype=object)
94-
self.assert_(
95-
np.array_equal(
96-
tslib.array_to_datetime(arr),
97-
np.array(
94+
self.assert_numpy_array_equal(
95+
tslib.array_to_datetime(arr),
96+
np.array(
9897
[
9998
'2013-01-01T00:00:00.000000000-0000',
10099
'2013-01-02T00:00:00.000000000-0000'
101100
],
102101
dtype='M8[ns]'
103-
)
104102
)
105103
)
106104

107105
arr = np.array(['Mon Sep 16 2013', 'Tue Sep 17 2013'], dtype=object)
108-
self.assert_(
109-
np.array_equal(
110-
tslib.array_to_datetime(arr),
111-
np.array(
106+
self.assert_numpy_array_equal(
107+
tslib.array_to_datetime(arr),
108+
np.array(
112109
[
113110
'2013-09-16T00:00:00.000000000-0000',
114111
'2013-09-17T00:00:00.000000000-0000'
115112
],
116113
dtype='M8[ns]'
117-
)
118114
)
119115
)
120116

@@ -155,16 +151,14 @@ def test_coercing_dates_outside_of_datetime64_ns_bounds(self):
155151
)
156152

157153
arr = np.array(['1/1/1000', '1/1/2000'], dtype=object)
158-
self.assert_(
159-
np.array_equal(
160-
tslib.array_to_datetime(arr, coerce=True),
161-
np.array(
154+
self.assert_numpy_array_equal(
155+
tslib.array_to_datetime(arr, coerce=True),
156+
np.array(
162157
[
163158
tslib.iNaT,
164159
'2000-01-01T00:00:00.000000000-0000'
165160
],
166161
dtype='M8[ns]'
167-
)
168162
)
169163
)
170164

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

178172
# With coercing, the invalid dates becomes iNaT
179-
self.assert_(
180-
np.array_equal(
181-
tslib.array_to_datetime(arr, coerce=True),
182-
np.array(
173+
self.assert_numpy_array_equal(
174+
tslib.array_to_datetime(arr, coerce=True),
175+
np.array(
183176
[
184177
'2013-01-01T00:00:00.000000000-0000',
185178
tslib.iNaT,
186179
tslib.iNaT
187180
],
188181
dtype='M8[ns]'
189-
)
190182
)
191183
)
192184

@@ -205,13 +197,11 @@ def test_parsing_timezone_offsets(self):
205197
)
206198

207199
for dt_string in dt_strings:
208-
self.assert_(
209-
np.array_equal(
210-
tslib.array_to_datetime(
211-
np.array([dt_string], dtype=object)
212-
),
213-
expected_output
214-
)
200+
self.assert_numpy_array_equal(
201+
tslib.array_to_datetime(
202+
np.array([dt_string], dtype=object)
203+
),
204+
expected_output
215205
)
216206

217207
class TestTimestampNsOperations(tm.TestCase):

0 commit comments

Comments
 (0)