Skip to content

TST/CLN: remove np.assert_equal #13263

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

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ if [ "$LINT" ]; then
if [ $? -ne "0" ]; then
RET=1
fi

done
grep -r --include '*.py' --exclude nosetester.py --exclude testing.py 'numpy.testing' pandas
if [ $? = "0" ]; then
RET=1
fi
else
echo "NOT Linting"
fi
Expand Down
23 changes: 13 additions & 10 deletions pandas/computation/tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from numpy.random import randn, rand, randint
import numpy as np
from numpy.testing import assert_allclose
from numpy.testing.decorators import slow

import pandas as pd
from pandas.core import common as com
Expand All @@ -33,7 +31,8 @@
import pandas.lib as lib
from pandas.util.testing import (assert_frame_equal, randbool,
assertRaisesRegexp, assert_numpy_array_equal,
assert_produces_warning, assert_series_equal)
assert_produces_warning, assert_series_equal,
slow)
from pandas.compat import PY3, u, reduce

_series_frame_incompatible = _bool_ops_syms
Expand Down Expand Up @@ -280,9 +279,13 @@ def check_modulus(self, lhs, arith1, rhs):
ex = 'lhs {0} rhs'.format(arith1)
result = pd.eval(ex, engine=self.engine, parser=self.parser)
expected = lhs % rhs
assert_allclose(result, expected)

tm.assert_almost_equal(result, expected)
expected = self.ne.evaluate('expected {0} rhs'.format(arith1))
assert_allclose(result, expected)
if isinstance(result, (DataFrame, Series)):
tm.assert_almost_equal(result.values, expected)
else:
tm.assert_almost_equal(result, expected.item())

def check_floor_division(self, lhs, arith1, rhs):
ex = 'lhs {0} rhs'.format(arith1)
Expand Down Expand Up @@ -319,13 +322,13 @@ def check_pow(self, lhs, arith1, rhs):
self.assertRaises(AssertionError, tm.assert_numpy_array_equal,
result, expected)
else:
assert_allclose(result, expected)
tm.assert_almost_equal(result, expected)

ex = '(lhs {0} rhs) {0} rhs'.format(arith1)
result = pd.eval(ex, engine=self.engine, parser=self.parser)
expected = self.get_expected_pow_result(
self.get_expected_pow_result(lhs, rhs), rhs)
assert_allclose(result, expected)
tm.assert_almost_equal(result, expected)

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

expected = lhs % rhs
assert_allclose(result, expected)
tm.assert_almost_equal(result, expected)

expected = _eval_single_bin(expected, arith1, rhs, self.engine)
assert_allclose(result, expected)
tm.assert_almost_equal(result, expected)

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

def test_df_use_case(self):
df = DataFrame({'a': np.random.randn(10),
Expand Down
10 changes: 5 additions & 5 deletions pandas/io/tests/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_frame_double_encoded_labels(self):
orient='index'))
df_unser = read_json(df.to_json(orient='records'), orient='records')
assert_index_equal(df.columns, df_unser.columns)
np.testing.assert_equal(df.values, df_unser.values)
tm.assert_numpy_array_equal(df.values, df_unser.values)

def test_frame_non_unique_index(self):
df = DataFrame([['a', 'b'], ['c', 'd']], index=[1, 1],
Expand All @@ -100,9 +100,9 @@ def test_frame_non_unique_index(self):
orient='split'))
unser = read_json(df.to_json(orient='records'), orient='records')
self.assertTrue(df.columns.equals(unser.columns))
np.testing.assert_equal(df.values, unser.values)
tm.assert_numpy_array_equal(df.values, unser.values)
unser = read_json(df.to_json(orient='values'), orient='values')
np.testing.assert_equal(df.values, unser.values)
tm.assert_numpy_array_equal(df.values, unser.values)

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

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

def test_series_from_json_to_json(self):

Expand Down
14 changes: 6 additions & 8 deletions pandas/io/tests/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import pandas.compat as compat

import numpy as np
from numpy.testing import (assert_array_almost_equal_nulp,
assert_approx_equal)
from pandas import DataFrame, Series, Index, NaT, DatetimeIndex
import pandas.util.testing as tm

Expand Down Expand Up @@ -1015,19 +1013,19 @@ def testFloatArray(self):
inpt = arr.astype(dtype)
outp = np.array(ujson.decode(ujson.encode(
inpt, double_precision=15)), dtype=dtype)
assert_array_almost_equal_nulp(inpt, outp)
tm.assert_almost_equal(inpt, outp)

def testFloatMax(self):
num = np.float(np.finfo(np.float).max / 10)
assert_approx_equal(np.float(ujson.decode(
tm.assert_almost_equal(np.float(ujson.decode(
ujson.encode(num, double_precision=15))), num, 15)

num = np.float32(np.finfo(np.float32).max / 10)
assert_approx_equal(np.float32(ujson.decode(
tm.assert_almost_equal(np.float32(ujson.decode(
ujson.encode(num, double_precision=15))), num, 15)

num = np.float64(np.finfo(np.float64).max / 10)
assert_approx_equal(np.float64(ujson.decode(
tm.assert_almost_equal(np.float64(ujson.decode(
ujson.encode(num, double_precision=15))), num, 15)

def testArrays(self):
Expand Down Expand Up @@ -1067,9 +1065,9 @@ def testArrays(self):
arr = np.arange(100.202, 200.202, 1, dtype=np.float32)
arr = arr.reshape((5, 5, 4))
outp = np.array(ujson.decode(ujson.encode(arr)), dtype=np.float32)
assert_array_almost_equal_nulp(arr, outp)
tm.assert_almost_equal(arr, outp)
outp = ujson.decode(ujson.encode(arr), numpy=True, dtype=np.float32)
assert_array_almost_equal_nulp(arr, outp)
tm.assert_almost_equal(arr, outp)

def testOdArray(self):
def will_raise():
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/tests/parser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import nose
import numpy as np
from numpy.testing.decorators import slow
from pandas.lib import Timestamp

import pandas as pd
Expand Down Expand Up @@ -607,7 +606,7 @@ def test_url(self):
tm.assert_frame_equal(url_table, local_table)
# TODO: ftp testing

@slow
@tm.slow
def test_file(self):

# FILE
Expand Down
9 changes: 4 additions & 5 deletions pandas/io/tests/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from numpy import nan
import numpy as np
from numpy.testing.decorators import slow

import pandas as pd
from pandas import DataFrame, Index, MultiIndex
Expand Down Expand Up @@ -544,7 +543,7 @@ def test_read_from_s3_url(self):
local_table = self.get_exceldf('test1')
tm.assert_frame_equal(url_table, local_table)

@slow
@tm.slow
def test_read_from_file_url(self):

# FILE
Expand Down Expand Up @@ -1102,9 +1101,9 @@ def test_sheets(self):
tm.assert_frame_equal(self.frame, recons)
recons = read_excel(reader, 'test2', index_col=0)
tm.assert_frame_equal(self.tsframe, recons)
np.testing.assert_equal(2, len(reader.sheet_names))
np.testing.assert_equal('test1', reader.sheet_names[0])
np.testing.assert_equal('test2', reader.sheet_names[1])
self.assertEqual(2, len(reader.sheet_names))
self.assertEqual('test1', reader.sheet_names[0])
self.assertEqual('test2', reader.sheet_names[1])

def test_colaliases(self):
_skip_if_no_xlrd()
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/tests/test_ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import nose
import pandas as pd
from pandas import compat
from pandas.util.testing import network, assert_frame_equal, with_connectivity_check
from numpy.testing.decorators import slow
from pandas.util.testing import (network, assert_frame_equal,
with_connectivity_check, slow)
import pandas.util.testing as tm

if compat.PY3:
Expand Down
41 changes: 20 additions & 21 deletions pandas/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import numpy as np
from numpy.random import rand
from numpy.testing.decorators import slow

from pandas import (DataFrame, MultiIndex, read_csv, Timestamp, Index,
date_range, Series)
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_spam_url(self):

assert_framelist_equal(df1, df2)

@slow
@tm.slow
def test_banklist(self):
df1 = self.read_html(self.banklist_data, '.*Florida.*',
attrs={'id': 'table'})
Expand Down Expand Up @@ -289,9 +288,9 @@ def test_invalid_url(self):
self.read_html('http://www.a23950sdfa908sd.com',
match='.*Water.*')
except ValueError as e:
tm.assert_equal(str(e), 'No tables found')
self.assertEqual(str(e), 'No tables found')

@slow
@tm.slow
def test_file_url(self):
url = self.banklist_data
dfs = self.read_html(file_path_to_url(url), 'First',
Expand All @@ -300,7 +299,7 @@ def test_file_url(self):
for df in dfs:
tm.assertIsInstance(df, DataFrame)

@slow
@tm.slow
def test_invalid_table_attrs(self):
url = self.banklist_data
with tm.assertRaisesRegexp(ValueError, 'No tables found'):
Expand All @@ -311,39 +310,39 @@ def _bank_data(self, *args, **kwargs):
return self.read_html(self.banklist_data, 'Metcalf',
attrs={'id': 'table'}, *args, **kwargs)

@slow
@tm.slow
def test_multiindex_header(self):
df = self._bank_data(header=[0, 1])[0]
tm.assertIsInstance(df.columns, MultiIndex)

@slow
@tm.slow
def test_multiindex_index(self):
df = self._bank_data(index_col=[0, 1])[0]
tm.assertIsInstance(df.index, MultiIndex)

@slow
@tm.slow
def test_multiindex_header_index(self):
df = self._bank_data(header=[0, 1], index_col=[0, 1])[0]
tm.assertIsInstance(df.columns, MultiIndex)
tm.assertIsInstance(df.index, MultiIndex)

@slow
@tm.slow
def test_multiindex_header_skiprows_tuples(self):
df = self._bank_data(header=[0, 1], skiprows=1, tupleize_cols=True)[0]
tm.assertIsInstance(df.columns, Index)

@slow
@tm.slow
def test_multiindex_header_skiprows(self):
df = self._bank_data(header=[0, 1], skiprows=1)[0]
tm.assertIsInstance(df.columns, MultiIndex)

@slow
@tm.slow
def test_multiindex_header_index_skiprows(self):
df = self._bank_data(header=[0, 1], index_col=[0, 1], skiprows=1)[0]
tm.assertIsInstance(df.index, MultiIndex)
tm.assertIsInstance(df.columns, MultiIndex)

@slow
@tm.slow
def test_regex_idempotency(self):
url = self.banklist_data
dfs = self.read_html(file_path_to_url(url),
Expand Down Expand Up @@ -371,7 +370,7 @@ def test_python_docs_table(self):
zz = [df.iloc[0, 0][0:4] for df in dfs]
self.assertEqual(sorted(zz), sorted(['Repo', 'What']))

@slow
@tm.slow
def test_thousands_macau_stats(self):
all_non_nan_table_index = -2
macau_data = os.path.join(DATA_PATH, 'macau.html')
Expand All @@ -381,7 +380,7 @@ def test_thousands_macau_stats(self):

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

@slow
@tm.slow
def test_thousands_macau_index_col(self):
all_non_nan_table_index = -2
macau_data = os.path.join(DATA_PATH, 'macau.html')
Expand Down Expand Up @@ -522,7 +521,7 @@ def test_nyse_wsj_commas_table(self):
self.assertEqual(df.shape[0], nrows)
self.assertTrue(df.columns.equals(columns))

@slow
@tm.slow
def test_banklist_header(self):
from pandas.io.html import _remove_whitespace

Expand Down Expand Up @@ -561,7 +560,7 @@ def try_remove_ws(x):
coerce=True)
tm.assert_frame_equal(converted, gtnew)

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

def test_bool_header_arg(self):
# GH 6114
Expand Down Expand Up @@ -753,7 +752,7 @@ def test_works_on_valid_markup(self):
tm.assertIsInstance(dfs, list)
tm.assertIsInstance(dfs[0], DataFrame)

@slow
@tm.slow
def test_fallback_success(self):
_skip_if_none_of(('bs4', 'html5lib'))
banklist_data = os.path.join(DATA_PATH, 'banklist.html')
Expand Down Expand Up @@ -796,7 +795,7 @@ def get_elements_from_file(url, element='table'):
return soup.find_all(element)


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


@slow
@tm.slow
def test_lxml_finds_tables():
filepath = os.path.join(DATA_PATH, "spam.html")
assert get_lxml_elements(filepath, 'table')


@slow
@tm.slow
def test_lxml_finds_tbody():
filepath = os.path.join(DATA_PATH, "spam.html")
assert get_lxml_elements(filepath, 'tbody')
Expand Down
Loading