Skip to content

Commit 9662d91

Browse files
sinhrksjreback
authored andcommitted
TST/CLN: remove np.assert_equal
Author: sinhrks <[email protected]> Closes #13263 from sinhrks/test_assert_equal and squashes the following commits: a5b2a67 [sinhrks] TST/CLN: remove np.assert_equal
1 parent 57ea76f commit 9662d91

38 files changed

+571
-579
lines changed

ci/lint.sh

+10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ if [ "$LINT" ]; then
1515
if [ $? -ne "0" ]; then
1616
RET=1
1717
fi
18+
1819
done
20+
echo "Linting DONE"
21+
22+
echo "Check for invalid testing"
23+
grep -r --include '*.py' --exclude nosetester.py --exclude testing.py 'numpy.testing' pandas
24+
if [ $? = "0" ]; then
25+
RET=1
26+
fi
27+
echo "Check for invalid testing DONE"
28+
1929
else
2030
echo "NOT Linting"
2131
fi

pandas/computation/tests/test_eval.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
from numpy.random import randn, rand, randint
1414
import numpy as np
15-
from numpy.testing import assert_allclose
16-
from numpy.testing.decorators import slow
1715

1816
import pandas as pd
1917
from pandas.core import common as com
@@ -33,7 +31,8 @@
3331
import pandas.lib as lib
3432
from pandas.util.testing import (assert_frame_equal, randbool,
3533
assertRaisesRegexp, assert_numpy_array_equal,
36-
assert_produces_warning, assert_series_equal)
34+
assert_produces_warning, assert_series_equal,
35+
slow)
3736
from pandas.compat import PY3, u, reduce
3837

3938
_series_frame_incompatible = _bool_ops_syms
@@ -280,9 +279,13 @@ def check_modulus(self, lhs, arith1, rhs):
280279
ex = 'lhs {0} rhs'.format(arith1)
281280
result = pd.eval(ex, engine=self.engine, parser=self.parser)
282281
expected = lhs % rhs
283-
assert_allclose(result, expected)
282+
283+
tm.assert_almost_equal(result, expected)
284284
expected = self.ne.evaluate('expected {0} rhs'.format(arith1))
285-
assert_allclose(result, expected)
285+
if isinstance(result, (DataFrame, Series)):
286+
tm.assert_almost_equal(result.values, expected)
287+
else:
288+
tm.assert_almost_equal(result, expected.item())
286289

287290
def check_floor_division(self, lhs, arith1, rhs):
288291
ex = 'lhs {0} rhs'.format(arith1)
@@ -319,13 +322,13 @@ def check_pow(self, lhs, arith1, rhs):
319322
self.assertRaises(AssertionError, tm.assert_numpy_array_equal,
320323
result, expected)
321324
else:
322-
assert_allclose(result, expected)
325+
tm.assert_almost_equal(result, expected)
323326

324327
ex = '(lhs {0} rhs) {0} rhs'.format(arith1)
325328
result = pd.eval(ex, engine=self.engine, parser=self.parser)
326329
expected = self.get_expected_pow_result(
327330
self.get_expected_pow_result(lhs, rhs), rhs)
328-
assert_allclose(result, expected)
331+
tm.assert_almost_equal(result, expected)
329332

330333
def check_single_invert_op(self, lhs, cmp1, rhs):
331334
# simple
@@ -701,10 +704,10 @@ def check_modulus(self, lhs, arith1, rhs):
701704
result = pd.eval(ex, engine=self.engine, parser=self.parser)
702705

703706
expected = lhs % rhs
704-
assert_allclose(result, expected)
707+
tm.assert_almost_equal(result, expected)
705708

706709
expected = _eval_single_bin(expected, arith1, rhs, self.engine)
707-
assert_allclose(result, expected)
710+
tm.assert_almost_equal(result, expected)
708711

709712
def check_alignment(self, result, nlhs, ghs, op):
710713
try:
@@ -1578,7 +1581,7 @@ def test_binary_functions(self):
15781581
expr = "{0}(a, b)".format(fn)
15791582
got = self.eval(expr)
15801583
expect = getattr(np, fn)(a, b)
1581-
np.testing.assert_allclose(got, expect)
1584+
tm.assert_almost_equal(got, expect, check_names=False)
15821585

15831586
def test_df_use_case(self):
15841587
df = DataFrame({'a': np.random.randn(10),

pandas/io/tests/json/test_pandas.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_frame_double_encoded_labels(self):
8787
orient='index'))
8888
df_unser = read_json(df.to_json(orient='records'), orient='records')
8989
assert_index_equal(df.columns, df_unser.columns)
90-
np.testing.assert_equal(df.values, df_unser.values)
90+
tm.assert_numpy_array_equal(df.values, df_unser.values)
9191

9292
def test_frame_non_unique_index(self):
9393
df = DataFrame([['a', 'b'], ['c', 'd']], index=[1, 1],
@@ -100,9 +100,9 @@ def test_frame_non_unique_index(self):
100100
orient='split'))
101101
unser = read_json(df.to_json(orient='records'), orient='records')
102102
self.assertTrue(df.columns.equals(unser.columns))
103-
np.testing.assert_equal(df.values, unser.values)
103+
tm.assert_numpy_array_equal(df.values, unser.values)
104104
unser = read_json(df.to_json(orient='values'), orient='values')
105-
np.testing.assert_equal(df.values, unser.values)
105+
tm.assert_numpy_array_equal(df.values, unser.values)
106106

107107
def test_frame_non_unique_columns(self):
108108
df = DataFrame([['a', 'b'], ['c', 'd']], index=[1, 2],
@@ -115,7 +115,7 @@ def test_frame_non_unique_columns(self):
115115
assert_frame_equal(df, read_json(df.to_json(orient='split'),
116116
orient='split', dtype=False))
117117
unser = read_json(df.to_json(orient='values'), orient='values')
118-
np.testing.assert_equal(df.values, unser.values)
118+
tm.assert_numpy_array_equal(df.values, unser.values)
119119

120120
# GH4377; duplicate columns not processing correctly
121121
df = DataFrame([['a', 'b'], ['c', 'd']], index=[
@@ -487,7 +487,7 @@ def test_series_non_unique_index(self):
487487
orient='split', typ='series'))
488488
unser = read_json(s.to_json(orient='records'),
489489
orient='records', typ='series')
490-
np.testing.assert_equal(s.values, unser.values)
490+
tm.assert_numpy_array_equal(s.values, unser.values)
491491

492492
def test_series_from_json_to_json(self):
493493

pandas/io/tests/json/test_ujson.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import pandas.compat as compat
2222

2323
import numpy as np
24-
from numpy.testing import (assert_array_almost_equal_nulp,
25-
assert_approx_equal)
2624
from pandas import DataFrame, Series, Index, NaT, DatetimeIndex
2725
import pandas.util.testing as tm
2826

@@ -1015,19 +1013,19 @@ def testFloatArray(self):
10151013
inpt = arr.astype(dtype)
10161014
outp = np.array(ujson.decode(ujson.encode(
10171015
inpt, double_precision=15)), dtype=dtype)
1018-
assert_array_almost_equal_nulp(inpt, outp)
1016+
tm.assert_almost_equal(inpt, outp)
10191017

10201018
def testFloatMax(self):
10211019
num = np.float(np.finfo(np.float).max / 10)
1022-
assert_approx_equal(np.float(ujson.decode(
1020+
tm.assert_almost_equal(np.float(ujson.decode(
10231021
ujson.encode(num, double_precision=15))), num, 15)
10241022

10251023
num = np.float32(np.finfo(np.float32).max / 10)
1026-
assert_approx_equal(np.float32(ujson.decode(
1024+
tm.assert_almost_equal(np.float32(ujson.decode(
10271025
ujson.encode(num, double_precision=15))), num, 15)
10281026

10291027
num = np.float64(np.finfo(np.float64).max / 10)
1030-
assert_approx_equal(np.float64(ujson.decode(
1028+
tm.assert_almost_equal(np.float64(ujson.decode(
10311029
ujson.encode(num, double_precision=15))), num, 15)
10321030

10331031
def testArrays(self):
@@ -1067,9 +1065,9 @@ def testArrays(self):
10671065
arr = np.arange(100.202, 200.202, 1, dtype=np.float32)
10681066
arr = arr.reshape((5, 5, 4))
10691067
outp = np.array(ujson.decode(ujson.encode(arr)), dtype=np.float32)
1070-
assert_array_almost_equal_nulp(arr, outp)
1068+
tm.assert_almost_equal(arr, outp)
10711069
outp = ujson.decode(ujson.encode(arr), numpy=True, dtype=np.float32)
1072-
assert_array_almost_equal_nulp(arr, outp)
1070+
tm.assert_almost_equal(arr, outp)
10731071

10741072
def testOdArray(self):
10751073
def will_raise():

pandas/io/tests/parser/common.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import nose
1212
import numpy as np
13-
from numpy.testing.decorators import slow
1413
from pandas.lib import Timestamp
1514

1615
import pandas as pd
@@ -607,7 +606,7 @@ def test_url(self):
607606
tm.assert_frame_equal(url_table, local_table)
608607
# TODO: ftp testing
609608

610-
@slow
609+
@tm.slow
611610
def test_file(self):
612611

613612
# FILE

pandas/io/tests/test_excel.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from numpy import nan
1515
import numpy as np
16-
from numpy.testing.decorators import slow
1716

1817
import pandas as pd
1918
from pandas import DataFrame, Index, MultiIndex
@@ -544,7 +543,7 @@ def test_read_from_s3_url(self):
544543
local_table = self.get_exceldf('test1')
545544
tm.assert_frame_equal(url_table, local_table)
546545

547-
@slow
546+
@tm.slow
548547
def test_read_from_file_url(self):
549548

550549
# FILE
@@ -1102,9 +1101,9 @@ def test_sheets(self):
11021101
tm.assert_frame_equal(self.frame, recons)
11031102
recons = read_excel(reader, 'test2', index_col=0)
11041103
tm.assert_frame_equal(self.tsframe, recons)
1105-
np.testing.assert_equal(2, len(reader.sheet_names))
1106-
np.testing.assert_equal('test1', reader.sheet_names[0])
1107-
np.testing.assert_equal('test2', reader.sheet_names[1])
1104+
self.assertEqual(2, len(reader.sheet_names))
1105+
self.assertEqual('test1', reader.sheet_names[0])
1106+
self.assertEqual('test2', reader.sheet_names[1])
11081107

11091108
def test_colaliases(self):
11101109
_skip_if_no_xlrd()

pandas/io/tests/test_ga.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import nose
88
import pandas as pd
99
from pandas import compat
10-
from pandas.util.testing import network, assert_frame_equal, with_connectivity_check
11-
from numpy.testing.decorators import slow
10+
from pandas.util.testing import (network, assert_frame_equal,
11+
with_connectivity_check, slow)
1212
import pandas.util.testing as tm
1313

1414
if compat.PY3:

pandas/io/tests/test_html.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import numpy as np
1818
from numpy.random import rand
19-
from numpy.testing.decorators import slow
2019

2120
from pandas import (DataFrame, MultiIndex, read_csv, Timestamp, Index,
2221
date_range, Series)
@@ -129,7 +128,7 @@ def test_spam_url(self):
129128

130129
assert_framelist_equal(df1, df2)
131130

132-
@slow
131+
@tm.slow
133132
def test_banklist(self):
134133
df1 = self.read_html(self.banklist_data, '.*Florida.*',
135134
attrs={'id': 'table'})
@@ -289,9 +288,9 @@ def test_invalid_url(self):
289288
self.read_html('http://www.a23950sdfa908sd.com',
290289
match='.*Water.*')
291290
except ValueError as e:
292-
tm.assert_equal(str(e), 'No tables found')
291+
self.assertEqual(str(e), 'No tables found')
293292

294-
@slow
293+
@tm.slow
295294
def test_file_url(self):
296295
url = self.banklist_data
297296
dfs = self.read_html(file_path_to_url(url), 'First',
@@ -300,7 +299,7 @@ def test_file_url(self):
300299
for df in dfs:
301300
tm.assertIsInstance(df, DataFrame)
302301

303-
@slow
302+
@tm.slow
304303
def test_invalid_table_attrs(self):
305304
url = self.banklist_data
306305
with tm.assertRaisesRegexp(ValueError, 'No tables found'):
@@ -311,39 +310,39 @@ def _bank_data(self, *args, **kwargs):
311310
return self.read_html(self.banklist_data, 'Metcalf',
312311
attrs={'id': 'table'}, *args, **kwargs)
313312

314-
@slow
313+
@tm.slow
315314
def test_multiindex_header(self):
316315
df = self._bank_data(header=[0, 1])[0]
317316
tm.assertIsInstance(df.columns, MultiIndex)
318317

319-
@slow
318+
@tm.slow
320319
def test_multiindex_index(self):
321320
df = self._bank_data(index_col=[0, 1])[0]
322321
tm.assertIsInstance(df.index, MultiIndex)
323322

324-
@slow
323+
@tm.slow
325324
def test_multiindex_header_index(self):
326325
df = self._bank_data(header=[0, 1], index_col=[0, 1])[0]
327326
tm.assertIsInstance(df.columns, MultiIndex)
328327
tm.assertIsInstance(df.index, MultiIndex)
329328

330-
@slow
329+
@tm.slow
331330
def test_multiindex_header_skiprows_tuples(self):
332331
df = self._bank_data(header=[0, 1], skiprows=1, tupleize_cols=True)[0]
333332
tm.assertIsInstance(df.columns, Index)
334333

335-
@slow
334+
@tm.slow
336335
def test_multiindex_header_skiprows(self):
337336
df = self._bank_data(header=[0, 1], skiprows=1)[0]
338337
tm.assertIsInstance(df.columns, MultiIndex)
339338

340-
@slow
339+
@tm.slow
341340
def test_multiindex_header_index_skiprows(self):
342341
df = self._bank_data(header=[0, 1], index_col=[0, 1], skiprows=1)[0]
343342
tm.assertIsInstance(df.index, MultiIndex)
344343
tm.assertIsInstance(df.columns, MultiIndex)
345344

346-
@slow
345+
@tm.slow
347346
def test_regex_idempotency(self):
348347
url = self.banklist_data
349348
dfs = self.read_html(file_path_to_url(url),
@@ -371,7 +370,7 @@ def test_python_docs_table(self):
371370
zz = [df.iloc[0, 0][0:4] for df in dfs]
372371
self.assertEqual(sorted(zz), sorted(['Repo', 'What']))
373372

374-
@slow
373+
@tm.slow
375374
def test_thousands_macau_stats(self):
376375
all_non_nan_table_index = -2
377376
macau_data = os.path.join(DATA_PATH, 'macau.html')
@@ -381,7 +380,7 @@ def test_thousands_macau_stats(self):
381380

382381
self.assertFalse(any(s.isnull().any() for _, s in df.iteritems()))
383382

384-
@slow
383+
@tm.slow
385384
def test_thousands_macau_index_col(self):
386385
all_non_nan_table_index = -2
387386
macau_data = os.path.join(DATA_PATH, 'macau.html')
@@ -522,7 +521,7 @@ def test_nyse_wsj_commas_table(self):
522521
self.assertEqual(df.shape[0], nrows)
523522
self.assertTrue(df.columns.equals(columns))
524523

525-
@slow
524+
@tm.slow
526525
def test_banklist_header(self):
527526
from pandas.io.html import _remove_whitespace
528527

@@ -561,7 +560,7 @@ def try_remove_ws(x):
561560
coerce=True)
562561
tm.assert_frame_equal(converted, gtnew)
563562

564-
@slow
563+
@tm.slow
565564
def test_gold_canyon(self):
566565
gc = 'Gold Canyon'
567566
with open(self.banklist_data, 'r') as f:
@@ -663,7 +662,7 @@ def test_wikipedia_states_table(self):
663662
assert os.path.isfile(data), '%r is not a file' % data
664663
assert os.path.getsize(data), '%r is an empty file' % data
665664
result = self.read_html(data, 'Arizona', header=1)[0]
666-
nose.tools.assert_equal(result['sq mi'].dtype, np.dtype('float64'))
665+
self.assertEqual(result['sq mi'].dtype, np.dtype('float64'))
667666

668667
def test_bool_header_arg(self):
669668
# GH 6114
@@ -753,7 +752,7 @@ def test_works_on_valid_markup(self):
753752
tm.assertIsInstance(dfs, list)
754753
tm.assertIsInstance(dfs[0], DataFrame)
755754

756-
@slow
755+
@tm.slow
757756
def test_fallback_success(self):
758757
_skip_if_none_of(('bs4', 'html5lib'))
759758
banklist_data = os.path.join(DATA_PATH, 'banklist.html')
@@ -796,7 +795,7 @@ def get_elements_from_file(url, element='table'):
796795
return soup.find_all(element)
797796

798797

799-
@slow
798+
@tm.slow
800799
def test_bs4_finds_tables():
801800
filepath = os.path.join(DATA_PATH, "spam.html")
802801
with warnings.catch_warnings():
@@ -811,13 +810,13 @@ def get_lxml_elements(url, element):
811810
return doc.xpath('.//{0}'.format(element))
812811

813812

814-
@slow
813+
@tm.slow
815814
def test_lxml_finds_tables():
816815
filepath = os.path.join(DATA_PATH, "spam.html")
817816
assert get_lxml_elements(filepath, 'table')
818817

819818

820-
@slow
819+
@tm.slow
821820
def test_lxml_finds_tbody():
822821
filepath = os.path.join(DATA_PATH, "spam.html")
823822
assert get_lxml_elements(filepath, 'tbody')

0 commit comments

Comments
 (0)