From 4ae02cfbd31ffa13ef7e9f95754c33c27dccfad7 Mon Sep 17 00:00:00 2001 From: sinhrks Date: Sun, 5 Jul 2015 08:03:47 +0900 Subject: [PATCH] TST: Deprecate assert_numpy_array_equivalent --- pandas/computation/tests/test_eval.py | 46 ++-- pandas/io/tests/test_data.py | 3 +- pandas/io/tests/test_json/test_ujson.py | 77 ++++--- pandas/io/tests/test_parsers.py | 3 +- pandas/sparse/tests/test_sparse.py | 6 +- pandas/stats/tests/test_moments.py | 12 +- pandas/tests/test_algos.py | 12 +- pandas/tests/test_base.py | 2 +- pandas/tests/test_expressions.py | 7 +- pandas/tests/test_frame.py | 16 +- pandas/tests/test_graphics.py | 28 +-- pandas/tests/test_groupby.py | 2 +- pandas/tests/test_index.py | 290 ++++++++++++------------ pandas/tests/test_indexing.py | 18 +- pandas/tests/test_internals.py | 6 +- pandas/tests/test_reshape.py | 3 +- pandas/tests/test_series.py | 10 +- pandas/tests/test_strings.py | 41 ++-- pandas/tests/test_testing.py | 5 +- pandas/tools/tests/test_tile.py | 36 ++- pandas/tseries/tests/test_period.py | 7 +- pandas/tseries/tests/test_plotting.py | 17 +- pandas/tseries/tests/test_timeseries.py | 9 +- pandas/util/testing.py | 37 +-- 24 files changed, 332 insertions(+), 361 deletions(-) diff --git a/pandas/computation/tests/test_eval.py b/pandas/computation/tests/test_eval.py index d455d9d0d8679..4f998319d922d 100644 --- a/pandas/computation/tests/test_eval.py +++ b/pandas/computation/tests/test_eval.py @@ -220,7 +220,7 @@ def check_complex_cmp_op(self, lhs, cmp1, rhs, binop, cmp2): expected = _eval_single_bin( lhs_new, binop, rhs_new, self.engine) result = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs): skip_these = _scalar_skip @@ -240,7 +240,7 @@ def check_operands(left, right, cmp_op): for ex in (ex1, ex2, ex3): result = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) def check_simple_cmp_op(self, lhs, cmp1, rhs): ex = 'lhs {0} rhs'.format(cmp1) @@ -251,13 +251,13 @@ def check_simple_cmp_op(self, lhs, cmp1, rhs): else: expected = _eval_single_bin(lhs, cmp1, rhs, self.engine) result = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) def check_binary_arith_op(self, lhs, arith1, rhs): ex = 'lhs {0} rhs'.format(arith1) result = pd.eval(ex, engine=self.engine, parser=self.parser) expected = _eval_single_bin(lhs, arith1, rhs, self.engine) - tm.assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) ex = 'lhs {0} rhs {0} rhs'.format(arith1) result = pd.eval(ex, engine=self.engine, parser=self.parser) nlhs = _eval_single_bin(lhs, arith1, rhs, @@ -273,7 +273,7 @@ def check_alignment(self, result, nlhs, ghs, op): pass else: expected = self.ne.evaluate('nlhs {0} ghs'.format(op)) - tm.assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) # modulus, pow, and floor division require special casing @@ -291,7 +291,7 @@ def check_floor_division(self, lhs, arith1, rhs): if self.engine == 'python': res = pd.eval(ex, engine=self.engine, parser=self.parser) expected = lhs // rhs - tm.assert_numpy_array_equivalent(res, expected) + tm.assert_numpy_array_equal(res, expected) else: self.assertRaises(TypeError, pd.eval, ex, local_dict={'lhs': lhs, 'rhs': rhs}, @@ -325,8 +325,8 @@ def check_pow(self, lhs, arith1, rhs): if (np.isscalar(lhs) and np.isscalar(rhs) and _is_py3_complex_incompat(result, expected)): - self.assertRaises(AssertionError, tm.assert_numpy_array_equivalent, result, - expected) + self.assertRaises(AssertionError, tm.assert_numpy_array_equal, + result, expected) else: assert_allclose(result, expected) @@ -345,12 +345,12 @@ def check_single_invert_op(self, lhs, cmp1, rhs): elb = np.array([bool(el)]) expected = ~elb result = pd.eval('~elb', engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(expected, result) + tm.assert_numpy_array_equal(expected, result) for engine in self.current_engines: tm.skip_if_no_ne(engine) - tm.assert_numpy_array_equivalent(result, pd.eval('~elb', engine=engine, - parser=self.parser)) + tm.assert_numpy_array_equal(result, pd.eval('~elb', engine=engine, + parser=self.parser)) def check_compound_invert_op(self, lhs, cmp1, rhs): skip_these = 'in', 'not in' @@ -370,13 +370,13 @@ def check_compound_invert_op(self, lhs, cmp1, rhs): else: expected = ~expected result = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(expected, result) + tm.assert_numpy_array_equal(expected, result) # make sure the other engines work the same as this one for engine in self.current_engines: tm.skip_if_no_ne(engine) ev = pd.eval(ex, engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(ev, result) + tm.assert_numpy_array_equal(ev, result) def ex(self, op, var_name='lhs'): return '{0}{1}'.format(op, var_name) @@ -639,17 +639,17 @@ def test_identical(self): x = np.array([1]) result = pd.eval('x', engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(result, np.array([1])) + tm.assert_numpy_array_equal(result, np.array([1])) self.assertEqual(result.shape, (1, )) x = np.array([1.5]) result = pd.eval('x', engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(result, np.array([1.5])) + tm.assert_numpy_array_equal(result, np.array([1.5])) self.assertEqual(result.shape, (1, )) x = np.array([False]) result = pd.eval('x', engine=self.engine, parser=self.parser) - tm.assert_numpy_array_equivalent(result, np.array([False])) + tm.assert_numpy_array_equal(result, np.array([False])) self.assertEqual(result.shape, (1, )) @@ -707,7 +707,7 @@ def check_alignment(self, result, nlhs, ghs, op): pass else: expected = eval('nlhs {0} ghs'.format(op)) - tm.assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) class TestEvalPythonPandas(TestEvalPythonPython): @@ -1118,10 +1118,10 @@ def test_truediv(self): if PY3: res = self.eval(ex, truediv=False) - tm.assert_numpy_array_equivalent(res, np.array([1.0])) + tm.assert_numpy_array_equal(res, np.array([1.0])) res = self.eval(ex, truediv=True) - tm.assert_numpy_array_equivalent(res, np.array([1.0])) + tm.assert_numpy_array_equal(res, np.array([1.0])) res = self.eval('1 / 2', truediv=True) expec = 0.5 @@ -1140,10 +1140,10 @@ def test_truediv(self): self.assertEqual(res, expec) else: res = self.eval(ex, truediv=False) - tm.assert_numpy_array_equivalent(res, np.array([1])) + tm.assert_numpy_array_equal(res, np.array([1])) res = self.eval(ex, truediv=True) - tm.assert_numpy_array_equivalent(res, np.array([1.0])) + tm.assert_numpy_array_equal(res, np.array([1.0])) res = self.eval('1 / 2', truediv=True) expec = 0.5 @@ -1446,8 +1446,8 @@ class TestScope(object): def check_global_scope(self, e, engine, parser): tm.skip_if_no_ne(engine) - tm.assert_numpy_array_equivalent(_var_s * 2, pd.eval(e, engine=engine, - parser=parser)) + tm.assert_numpy_array_equal(_var_s * 2, pd.eval(e, engine=engine, + parser=parser)) def test_global_scope(self): e = '_var_s * 2' diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index 63ed26ea7d931..ddc588d218312 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -14,7 +14,6 @@ from pandas.util.testing import (assert_series_equal, assert_produces_warning, network, assert_frame_equal) import pandas.util.testing as tm -from numpy.testing import assert_array_equal if compat.PY3: from urllib.error import HTTPError @@ -533,7 +532,7 @@ def test_fred_part2(self): [848.3], [933.3]] result = web.get_data_fred("A09024USA144NNBR", start="1915").ix[:5] - assert_array_equal(result.values, np.array(expected)) + tm.assert_numpy_array_equal(result.values, np.array(expected)) @network def test_invalid_series(self): diff --git a/pandas/io/tests/test_json/test_ujson.py b/pandas/io/tests/test_json/test_ujson.py index cb99c1705c5eb..43e1c5c89dd5e 100644 --- a/pandas/io/tests/test_json/test_ujson.py +++ b/pandas/io/tests/test_json/test_ujson.py @@ -21,8 +21,7 @@ import pandas.compat as compat import numpy as np -from numpy.testing import (assert_array_equal, - assert_array_almost_equal_nulp, +from numpy.testing import (assert_array_almost_equal_nulp, assert_approx_equal) import pytz import dateutil @@ -166,7 +165,7 @@ def test_encodeArrayOfNestedArrays(self): #self.assertEqual(output, json.dumps(input)) self.assertEqual(input, ujson.decode(output)) input = np.array(input) - assert_array_equal(input, ujson.decode(output, numpy=True, dtype=input.dtype)) + tm.assert_numpy_array_equal(input, ujson.decode(output, numpy=True, dtype=input.dtype)) def test_encodeArrayOfDoubles(self): input = [ 31337.31337, 31337.31337, 31337.31337, 31337.31337] * 10 @@ -174,7 +173,7 @@ def test_encodeArrayOfDoubles(self): self.assertEqual(input, json.loads(output)) #self.assertEqual(output, json.dumps(input)) self.assertEqual(input, ujson.decode(output)) - assert_array_equal(np.array(input), ujson.decode(output, numpy=True)) + tm.assert_numpy_array_equal(np.array(input), ujson.decode(output, numpy=True)) def test_doublePrecisionTest(self): input = 30.012345678901234 @@ -271,7 +270,7 @@ def test_encodeArrayInArray(self): self.assertEqual(input, json.loads(output)) self.assertEqual(output, json.dumps(input)) self.assertEqual(input, ujson.decode(output)) - assert_array_equal(np.array(input), ujson.decode(output, numpy=True)) + tm.assert_numpy_array_equal(np.array(input), ujson.decode(output, numpy=True)) pass def test_encodeIntConversion(self): @@ -307,7 +306,7 @@ def test_encodeListConversion(self): output = ujson.encode(input) self.assertEqual(input, json.loads(output)) self.assertEqual(input, ujson.decode(output)) - assert_array_equal(np.array(input), ujson.decode(output, numpy=True)) + tm.assert_numpy_array_equal(np.array(input), ujson.decode(output, numpy=True)) pass def test_encodeDictConversion(self): @@ -676,8 +675,8 @@ def test_encodeListLongConversion(self): output = ujson.encode(input) self.assertEqual(input, json.loads(output)) self.assertEqual(input, ujson.decode(output)) - assert_array_equal(np.array(input), ujson.decode(output, numpy=True, - dtype=np.int64)) + tm.assert_numpy_array_equal(np.array(input), ujson.decode(output, numpy=True, + dtype=np.int64)) pass def test_encodeLongConversion(self): @@ -755,7 +754,7 @@ def test_loadFile(self): f = StringIO("[1,2,3,4]") self.assertEqual([1, 2, 3, 4], ujson.load(f)) f = StringIO("[1,2,3,4]") - assert_array_equal(np.array([1, 2, 3, 4]), ujson.load(f, numpy=True)) + tm.assert_numpy_array_equal(np.array([1, 2, 3, 4]), ujson.load(f, numpy=True)) def test_loadFileLikeObject(self): class filelike: @@ -768,7 +767,7 @@ def read(self): f = filelike() self.assertEqual([1, 2, 3, 4], ujson.load(f)) f = filelike() - assert_array_equal(np.array([1, 2, 3, 4]), ujson.load(f, numpy=True)) + tm.assert_numpy_array_equal(np.array([1, 2, 3, 4]), ujson.load(f, numpy=True)) def test_loadFileArgsError(self): try: @@ -906,7 +905,7 @@ def testBoolArray(self): inpt = np.array([True, False, True, True, False, True, False , False], dtype=np.bool) outp = np.array(ujson.decode(ujson.encode(inpt)), dtype=np.bool) - assert_array_equal(inpt, outp) + tm.assert_numpy_array_equal(inpt, outp) def testInt(self): num = np.int(2562010) @@ -943,7 +942,7 @@ def testIntArray(self): for dtype in dtypes: inpt = arr.astype(dtype) outp = np.array(ujson.decode(ujson.encode(inpt)), dtype=dtype) - assert_array_equal(inpt, outp) + tm.assert_numpy_array_equal(inpt, outp) def testIntMax(self): num = np.int(np.iinfo(np.int).max) @@ -1008,26 +1007,26 @@ def testArrays(self): arr = np.arange(100); arr = arr.reshape((10, 10)) - assert_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) - assert_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) + tm.assert_numpy_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) + tm.assert_numpy_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) arr = arr.reshape((5, 5, 4)) - assert_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) - assert_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) + tm.assert_numpy_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) + tm.assert_numpy_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) arr = arr.reshape((100, 1)) - assert_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) - assert_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) + tm.assert_numpy_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) + tm.assert_numpy_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) arr = np.arange(96); arr = arr.reshape((2, 2, 2, 2, 3, 2)) - assert_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) - assert_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) + tm.assert_numpy_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) + tm.assert_numpy_array_equal(ujson.decode(ujson.encode(arr), numpy=True), arr) l = ['a', list(), dict(), dict(), list(), 42, 97.8, ['a', 'b'], {'key': 'val'}] arr = np.array(l) - assert_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) + tm.assert_numpy_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr) arr = np.arange(100.202, 200.202, 1, dtype=np.float32); arr = arr.reshape((5, 5, 4)) @@ -1158,19 +1157,19 @@ def testDataFrame(self): # column indexed outp = DataFrame(ujson.decode(ujson.encode(df))) self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) - assert_array_equal(df.index, outp.index) + tm.assert_numpy_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.index, outp.index) dec = _clean_dict(ujson.decode(ujson.encode(df, orient="split"))) outp = DataFrame(**dec) self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) - assert_array_equal(df.index, outp.index) + tm.assert_numpy_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.index, outp.index) outp = DataFrame(ujson.decode(ujson.encode(df, orient="records"))) outp.index = df.index self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.columns, outp.columns) outp = DataFrame(ujson.decode(ujson.encode(df, orient="values"))) outp.index = df.index @@ -1178,8 +1177,8 @@ def testDataFrame(self): outp = DataFrame(ujson.decode(ujson.encode(df, orient="index"))) self.assertTrue((df.transpose() == outp).values.all()) - assert_array_equal(df.transpose().columns, outp.columns) - assert_array_equal(df.transpose().index, outp.index) + tm.assert_numpy_array_equal(df.transpose().columns, outp.columns) + tm.assert_numpy_array_equal(df.transpose().index, outp.index) def testDataFrameNumpy(self): df = DataFrame([[1,2,3], [4,5,6]], index=['a', 'b'], columns=['x', 'y', 'z']) @@ -1187,20 +1186,20 @@ def testDataFrameNumpy(self): # column indexed outp = DataFrame(ujson.decode(ujson.encode(df), numpy=True)) self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) - assert_array_equal(df.index, outp.index) + tm.assert_numpy_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.index, outp.index) dec = _clean_dict(ujson.decode(ujson.encode(df, orient="split"), numpy=True)) outp = DataFrame(**dec) self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) - assert_array_equal(df.index, outp.index) + tm.assert_numpy_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.index, outp.index) outp = DataFrame(ujson.decode(ujson.encode(df, orient="index"), numpy=True)) self.assertTrue((df.transpose() == outp).values.all()) - assert_array_equal(df.transpose().columns, outp.columns) - assert_array_equal(df.transpose().index, outp.index) + tm.assert_numpy_array_equal(df.transpose().columns, outp.columns) + tm.assert_numpy_array_equal(df.transpose().index, outp.index) def testDataFrameNested(self): df = DataFrame([[1,2,3], [4,5,6]], index=['a', 'b'], columns=['x', 'y', 'z']) @@ -1233,18 +1232,18 @@ def testDataFrameNumpyLabelled(self): # column indexed outp = DataFrame(*ujson.decode(ujson.encode(df), numpy=True, labelled=True)) self.assertTrue((df.T == outp).values.all()) - assert_array_equal(df.T.columns, outp.columns) - assert_array_equal(df.T.index, outp.index) + tm.assert_numpy_array_equal(df.T.columns, outp.columns) + tm.assert_numpy_array_equal(df.T.index, outp.index) outp = DataFrame(*ujson.decode(ujson.encode(df, orient="records"), numpy=True, labelled=True)) outp.index = df.index self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.columns, outp.columns) outp = DataFrame(*ujson.decode(ujson.encode(df, orient="index"), numpy=True, labelled=True)) self.assertTrue((df == outp).values.all()) - assert_array_equal(df.columns, outp.columns) - assert_array_equal(df.index, outp.index) + tm.assert_numpy_array_equal(df.columns, outp.columns) + tm.assert_numpy_array_equal(df.index, outp.index) def testSeries(self): s = Series([10, 20, 30, 40, 50, 60], name="series", index=[6,7,8,9,10,15]) diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 64f923be8ad77..facbff5e047db 100755 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -33,7 +33,6 @@ import pandas.tseries.tools as tools from numpy.testing.decorators import slow -from numpy.testing import assert_array_equal import pandas.parser @@ -747,7 +746,7 @@ def test_default_na_values(self): _NA_VALUES = set(['-1.#IND', '1.#QNAN', '1.#IND', '-1.#QNAN', '#N/A','N/A', 'NA', '#NA', 'NULL', 'NaN', 'nan', '-NaN', '-nan', '#N/A N/A','']) - assert_array_equal (_NA_VALUES, parsers._NA_VALUES) + self.assertEqual(_NA_VALUES, parsers._NA_VALUES) nv = len(_NA_VALUES) def f(i, v): if i == 0: diff --git a/pandas/sparse/tests/test_sparse.py b/pandas/sparse/tests/test_sparse.py index 788e4bd7ef80a..cadf008fb40fb 100644 --- a/pandas/sparse/tests/test_sparse.py +++ b/pandas/sparse/tests/test_sparse.py @@ -13,7 +13,7 @@ from pandas.util.testing import (assert_almost_equal, assert_series_equal, assert_frame_equal, assert_panel_equal, assertRaisesRegexp, - assert_array_equal, assert_attr_equal) + assert_numpy_array_equal, assert_attr_equal) from numpy.testing import assert_equal from pandas import Series, DataFrame, bdate_range, Panel, MultiIndex @@ -575,7 +575,7 @@ def _compare_with_series(sps, new_index): reindexed = self.bseries.reindex(self.bseries.index, copy=False) reindexed.sp_values[:] = 1. - np.testing.assert_array_equal(self.bseries.sp_values, 1.) + tm.assert_numpy_array_equal(self.bseries.sp_values, np.repeat(1., 10)) def test_sparse_reindex(self): length = 10 @@ -899,7 +899,7 @@ def _check_results_to_coo(results, check): (A, il, jl) = results (A_result, il_result, jl_result) = check # convert to dense and compare - assert_array_equal(A.todense(), A_result.todense()) + assert_numpy_array_equal(A.todense(), A_result.todense()) # or compare directly as difference of sparse # assert(abs(A - A_result).max() < 1e-12) # max is failing in python # 2.6 diff --git a/pandas/stats/tests/test_moments.py b/pandas/stats/tests/test_moments.py index 1741676abf773..bb6cb5a444dd9 100644 --- a/pandas/stats/tests/test_moments.py +++ b/pandas/stats/tests/test_moments.py @@ -539,7 +539,7 @@ def _check_ndarray(self, func, static_comp, window=50, result = func(arr, 20, center=True) expected = func(np.concatenate((arr, np.array([np.NaN] * 9))), 20)[9:] - self.assert_numpy_array_equivalent(result, expected) + self.assert_numpy_array_equal(result, expected) if test_stable: result = func(self.arr + 1e9, window) @@ -1684,7 +1684,7 @@ def test_pairwise_stats_column_names_order(self): assert_index_equal(result.columns, df.columns) for i, result in enumerate(results): if i > 0: - self.assert_numpy_array_equivalent(result, results[0]) + self.assert_numpy_array_equal(result, results[0]) # DataFrame with itself, pairwise=True for f in [lambda x: mom.expanding_cov(x, pairwise=True), @@ -1701,7 +1701,7 @@ def test_pairwise_stats_column_names_order(self): assert_index_equal(result.minor_axis, df.columns) for i, result in enumerate(results): if i > 0: - self.assert_numpy_array_equivalent(result, results[0]) + self.assert_numpy_array_equal(result, results[0]) # DataFrame with itself, pairwise=False for f in [lambda x: mom.expanding_cov(x, pairwise=False), @@ -1717,7 +1717,7 @@ def test_pairwise_stats_column_names_order(self): assert_index_equal(result.columns, df.columns) for i, result in enumerate(results): if i > 0: - self.assert_numpy_array_equivalent(result, results[0]) + self.assert_numpy_array_equal(result, results[0]) # DataFrame with another DataFrame, pairwise=True for f in [lambda x, y: mom.expanding_cov(x, y, pairwise=True), @@ -1734,7 +1734,7 @@ def test_pairwise_stats_column_names_order(self): assert_index_equal(result.minor_axis, df2.columns) for i, result in enumerate(results): if i > 0: - self.assert_numpy_array_equivalent(result, results[0]) + self.assert_numpy_array_equal(result, results[0]) # DataFrame with another DataFrame, pairwise=False for f in [lambda x, y: mom.expanding_cov(x, y, pairwise=False), @@ -1769,7 +1769,7 @@ def test_pairwise_stats_column_names_order(self): assert_index_equal(result.columns, df.columns) for i, result in enumerate(results): if i > 0: - self.assert_numpy_array_equivalent(result, results[0]) + self.assert_numpy_array_equal(result, results[0]) def test_rolling_skew_edge_cases(self): diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 91b03aceaa14c..cb5687acf3a34 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -305,7 +305,7 @@ def test_group_var_generic_1d(self): self.algo(out, counts, values, labels) np.testing.assert_allclose(out, expected_out, self.rtol) - tm.assert_array_equal(counts, expected_counts) + tm.assert_numpy_array_equal(counts, expected_counts) def test_group_var_generic_1d_flat_labels(self): prng = RandomState(1234) @@ -321,7 +321,7 @@ def test_group_var_generic_1d_flat_labels(self): self.algo(out, counts, values, labels) np.testing.assert_allclose(out, expected_out, self.rtol) - tm.assert_array_equal(counts, expected_counts) + tm.assert_numpy_array_equal(counts, expected_counts) def test_group_var_generic_2d_all_finite(self): prng = RandomState(1234) @@ -337,7 +337,7 @@ def test_group_var_generic_2d_all_finite(self): self.algo(out, counts, values, labels) np.testing.assert_allclose(out, expected_out, self.rtol) - tm.assert_array_equal(counts, expected_counts) + tm.assert_numpy_array_equal(counts, expected_counts) def test_group_var_generic_2d_some_nan(self): prng = RandomState(1234) @@ -356,7 +356,7 @@ def test_group_var_generic_2d_some_nan(self): self.algo(out, counts, values, labels) np.testing.assert_allclose(out, expected_out, self.rtol) - tm.assert_array_equal(counts, expected_counts) + tm.assert_numpy_array_equal(counts, expected_counts) def test_group_var_constant(self): # Regression test from GH 10448. @@ -421,12 +421,12 @@ def test_unique_label_indices(): left = unique_label_indices(a) right = np.unique(a, return_index=True)[1] - tm.assert_array_equal(left, right) + tm.assert_numpy_array_equal(left, right) a[np.random.choice(len(a), 10)] = -1 left= unique_label_indices(a) right = np.unique(a, return_index=True)[1][1:] - tm.assert_array_equal(left, right) + tm.assert_numpy_array_equal(left, right) if __name__ == '__main__': import nose diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index db23b13edd42b..d47e7dbe751c7 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -553,7 +553,7 @@ def test_value_counts_inferred(self): expected = Series([4, 3, 2], index=['b', 'a', 'd']) tm.assert_series_equal(s.value_counts(), expected) - self.assert_numpy_array_equivalent(s.unique(), np.array(['a', 'b', np.nan, 'd'], dtype='O')) + self.assert_numpy_array_equal(s.unique(), np.array(['a', 'b', np.nan, 'd'], dtype='O')) self.assertEqual(s.nunique(), 3) s = klass({}) diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index 86831a8485786..1ca23c124e250 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -9,7 +9,6 @@ import operator import numpy as np -from numpy.testing import assert_array_equal from pandas.core.api import DataFrame, Panel from pandas.computation import expressions as expr @@ -271,7 +270,7 @@ def testit(): result = expr.evaluate(op, op_str, f, f, use_numexpr=True) expected = expr.evaluate(op, op_str, f, f, use_numexpr=False) - assert_array_equal(result,expected.values) + tm.assert_numpy_array_equal(result,expected.values) result = expr._can_use_numexpr(op, op_str, f2, f2, 'evaluate') self.assertFalse(result) @@ -306,7 +305,7 @@ def testit(): result = expr.evaluate(op, op_str, f11, f12, use_numexpr=True) expected = expr.evaluate(op, op_str, f11, f12, use_numexpr=False) - assert_array_equal(result,expected.values) + tm.assert_numpy_array_equal(result,expected.values) result = expr._can_use_numexpr(op, op_str, f21, f22, 'evaluate') self.assertFalse(result) @@ -331,7 +330,7 @@ def testit(): c.fill(cond) result = expr.where(c, f.values, f.values+1) expected = np.where(c, f.values, f.values+1) - assert_array_equal(result,expected) + tm.assert_numpy_array_equal(result,expected) expr.set_use_numexpr(False) testit() diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 2a7022da4fdc4..9ab004eb31a99 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -24,7 +24,6 @@ from numpy.random import randn import numpy as np import numpy.ma as ma -from numpy.testing import assert_array_equal import numpy.ma.mrecords as mrecords import pandas.core.nanops as nanops @@ -40,6 +39,7 @@ from pandas.util.misc import is_little_endian from pandas.util.testing import (assert_almost_equal, + assert_numpy_array_equal, assert_series_equal, assert_frame_equal, assertRaisesRegexp, @@ -125,7 +125,7 @@ def test_getitem(self): df['@awesome_domain'] = ad self.assertRaises(KeyError, df.__getitem__, 'df["$10"]') res = df['@awesome_domain'] - assert_array_equal(ad, res.values) + assert_numpy_array_equal(ad, res.values) def test_getitem_dupe_cols(self): df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b']) @@ -4664,13 +4664,13 @@ def test_from_records_empty(self): def test_from_records_empty_with_nonempty_fields_gh3682(self): a = np.array([(1, 2)], dtype=[('id', np.int64), ('value', np.int64)]) df = DataFrame.from_records(a, index='id') - assert_array_equal(df.index, Index([1], name='id')) + assert_numpy_array_equal(df.index, Index([1], name='id')) self.assertEqual(df.index.name, 'id') - assert_array_equal(df.columns, Index(['value'])) + assert_numpy_array_equal(df.columns, Index(['value'])) b = np.array([], dtype=[('id', np.int64), ('value', np.int64)]) df = DataFrame.from_records(b, index='id') - assert_array_equal(df.index, Index([], name='id')) + assert_numpy_array_equal(df.index, Index([], name='id')) self.assertEqual(df.index.name, 'id') def test_from_records_with_datetimes(self): @@ -6108,7 +6108,7 @@ def test_boolean_comparison(self): assert_frame_equal(result,expected) result = df.values>b - assert_array_equal(result,expected.values) + assert_numpy_array_equal(result,expected.values) result = df>l assert_frame_equal(result,expected) @@ -6120,7 +6120,7 @@ def test_boolean_comparison(self): assert_frame_equal(result,expected) result = df.values>b_r - assert_array_equal(result,expected.values) + assert_numpy_array_equal(result,expected.values) self.assertRaises(ValueError, df.__gt__, b_c) self.assertRaises(ValueError, df.values.__gt__, b_c) @@ -6140,7 +6140,7 @@ def test_boolean_comparison(self): assert_frame_equal(result,expected) result = df.values == b_r - assert_array_equal(result,expected.values) + assert_numpy_array_equal(result,expected.values) self.assertRaises(ValueError, lambda : df == b_c) self.assertFalse((df.values == b_c)) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 800c6f83f4902..da481d71aa59c 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -25,7 +25,7 @@ from numpy import random from numpy.random import rand, randn -from numpy.testing import assert_array_equal, assert_allclose +from numpy.testing import assert_allclose from numpy.testing.decorators import slow import pandas.tools.plotting as plotting @@ -646,11 +646,11 @@ def test_bar_log(self): expected = np.hstack((.1, expected, 1e4)) ax = Series([200, 500]).plot(log=True, kind='bar') - assert_array_equal(ax.yaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), expected) tm.close() ax = Series([200, 500]).plot(log=True, kind='barh') - assert_array_equal(ax.xaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax.xaxis.get_ticklocs(), expected) tm.close() # GH 9905 @@ -660,13 +660,13 @@ def test_bar_log(self): expected = np.hstack((1.0e-04, expected, 1.0e+01)) ax = Series([0.1, 0.01, 0.001]).plot(log=True, kind='bar') - assert_array_equal(ax.get_ylim(), (0.001, 0.10000000000000001)) - assert_array_equal(ax.yaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax.get_ylim(), (0.001, 0.10000000000000001)) + tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), expected) tm.close() ax = Series([0.1, 0.01, 0.001]).plot(log=True, kind='barh') - assert_array_equal(ax.get_xlim(), (0.001, 0.10000000000000001)) - assert_array_equal(ax.xaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax.get_xlim(), (0.001, 0.10000000000000001)) + tm.assert_numpy_array_equal(ax.xaxis.get_ticklocs(), expected) @slow def test_bar_ignore_index(self): @@ -2154,7 +2154,7 @@ def test_bar_log_no_subplots(self): # no subplots df = DataFrame({'A': [3] * 5, 'B': lrange(1, 6)}, index=lrange(5)) ax = df.plot(kind='bar', grid=True, log=True) - assert_array_equal(ax.yaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), expected) @slow def test_bar_log_subplots(self): @@ -2166,8 +2166,8 @@ def test_bar_log_subplots(self): Series([300, 500])]).plot(log=True, kind='bar', subplots=True) - assert_array_equal(ax[0].yaxis.get_ticklocs(), expected) - assert_array_equal(ax[1].yaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax[0].yaxis.get_ticklocs(), expected) + tm.assert_numpy_array_equal(ax[1].yaxis.get_ticklocs(), expected) @slow def test_boxplot(self): @@ -2178,7 +2178,7 @@ def test_boxplot(self): ax = _check_plot_works(df.plot, kind='box') self._check_text_labels(ax.get_xticklabels(), labels) - assert_array_equal(ax.xaxis.get_ticklocs(), + tm.assert_numpy_array_equal(ax.xaxis.get_ticklocs(), np.arange(1, len(numeric_cols) + 1)) self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols)) @@ -2205,7 +2205,7 @@ def test_boxplot(self): numeric_cols = df._get_numeric_data().columns labels = [com.pprint_thing(c) for c in numeric_cols] self._check_text_labels(ax.get_xticklabels(), labels) - assert_array_equal(ax.xaxis.get_ticklocs(), positions) + tm.assert_numpy_array_equal(ax.xaxis.get_ticklocs(), positions) self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols)) @slow @@ -2231,7 +2231,7 @@ def test_boxplot_vertical(self): positions = np.array([3, 2, 8]) ax = df.plot(kind='box', positions=positions, vert=False) self._check_text_labels(ax.get_yticklabels(), labels) - assert_array_equal(ax.yaxis.get_ticklocs(), positions) + tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), positions) self.assertEqual(len(ax.lines), self.bp_n_objects * len(numeric_cols)) @slow @@ -2888,7 +2888,7 @@ def test_unordered_ts(self): xticks = ax.lines[0].get_xdata() self.assertTrue(xticks[0] < xticks[1]) ydata = ax.lines[0].get_ydata() - assert_array_equal(ydata, np.array([1.0, 2.0, 3.0])) + tm.assert_numpy_array_equal(ydata, np.array([1.0, 2.0, 3.0])) def test_all_invalid_plot_data(self): df = DataFrame(list('abcd')) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index f1df0d711b5d0..c0b5bcd55d873 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -3735,7 +3735,7 @@ def test_groupby_categorical_no_compress(self): result = data.groupby("b").mean() result = result["a"].values exp = np.array([1,2,4,np.nan]) - self.assert_numpy_array_equivalent(result, exp) + self.assert_numpy_array_equal(result, exp) def test_groupby_non_arithmetic_agg_types(self): # GH9311, GH6620 diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 81c6366b4cb41..87e06bad7fbe1 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -16,7 +16,7 @@ CategoricalIndex, DatetimeIndex, TimedeltaIndex, PeriodIndex) from pandas.core.index import InvalidIndexError, NumericIndex from pandas.util.testing import (assert_almost_equal, assertRaisesRegexp, - assert_copy, assert_numpy_array_equivalent, assert_numpy_array_equal) + assert_copy) from pandas import compat from pandas.compat import long, is_platform_windows @@ -100,7 +100,7 @@ def test_reindex_base(self): expected = np.arange(idx.size) actual = idx.get_indexer(idx) - assert_numpy_array_equivalent(expected, actual) + tm.assert_numpy_array_equal(expected, actual) with tm.assertRaisesRegexp(ValueError, 'Invalid fill method'): idx.get_indexer(idx, method='invalid') @@ -247,7 +247,7 @@ def test_argsort(self): result = ind.argsort() expected = np.array(ind).argsort() - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) def test_pickle(self): for ind in self.indices.values(): @@ -357,7 +357,7 @@ def test_difference_base(self): pass elif isinstance(idx, (DatetimeIndex, TimedeltaIndex)): self.assertEqual(result.__class__, answer.__class__) - self.assert_numpy_array_equal(result.asi8, answer.asi8) + tm.assert_numpy_array_equal(result.asi8, answer.asi8) else: result = first.difference(case) self.assertTrue(tm.equalContents(result, answer)) @@ -443,8 +443,8 @@ def test_equals_op(self): index_a == index_b expected1 = np.array([True] * n) expected2 = np.array([True] * (n - 1) + [False]) - assert_numpy_array_equivalent(index_a == index_a, expected1) - assert_numpy_array_equivalent(index_a == index_c, expected2) + tm.assert_numpy_array_equal(index_a == index_a, expected1) + tm.assert_numpy_array_equal(index_a == index_c, expected2) # test comparisons with numpy arrays array_a = np.array(index_a) @@ -453,8 +453,8 @@ def test_equals_op(self): array_d = np.array(index_a[0:1]) with tm.assertRaisesRegexp(ValueError, "Lengths must match"): index_a == array_b - assert_numpy_array_equivalent(index_a == array_a, expected1) - assert_numpy_array_equivalent(index_a == array_c, expected2) + tm.assert_numpy_array_equal(index_a == array_a, expected1) + tm.assert_numpy_array_equal(index_a == array_c, expected2) # test comparisons with Series series_a = Series(array_a) @@ -463,8 +463,8 @@ def test_equals_op(self): series_d = Series(array_d) with tm.assertRaisesRegexp(ValueError, "Lengths must match"): index_a == series_b - assert_numpy_array_equivalent(index_a == series_a, expected1) - assert_numpy_array_equivalent(index_a == series_c, expected2) + tm.assert_numpy_array_equal(index_a == series_a, expected1) + tm.assert_numpy_array_equal(index_a == series_c, expected2) # cases where length is 1 for one of them with tm.assertRaisesRegexp(ValueError, "Lengths must match"): @@ -486,8 +486,8 @@ def test_equals_op(self): expected3 = np.array([False] * (len(index_a) - 2) + [True, False]) # assuming the 2nd to last item is unique in the data item = index_a[-2] - assert_numpy_array_equivalent(index_a == item, expected3) - assert_numpy_array_equivalent(series_a == item, expected3) + tm.assert_numpy_array_equal(index_a == item, expected3) + tm.assert_numpy_array_equal(series_a == item, expected3) class TestIndex(Base, tm.TestCase): @@ -534,14 +534,14 @@ def test_constructor(self): arr = np.array(self.strIndex) index = Index(arr) tm.assert_contains_all(arr, index) - self.assert_numpy_array_equal(self.strIndex, index) + tm.assert_numpy_array_equal(self.strIndex, index) # copy arr = np.array(self.strIndex) index = Index(arr, copy=True, name='name') tm.assertIsInstance(index, Index) self.assertEqual(index.name, 'name') - assert_numpy_array_equivalent(arr, index) + tm.assert_numpy_array_equal(arr, index) arr[0] = "SOMEBIGLONGSTRING" self.assertNotEqual(index[0], "SOMEBIGLONGSTRING") @@ -598,7 +598,7 @@ def __array__(self, dtype=None): def test_index_ctor_infer_periodindex(self): xp = period_range('2012-1-1', freq='M', periods=3) rs = Index(xp) - assert_numpy_array_equivalent(rs, xp) + tm.assert_numpy_array_equal(rs, xp) tm.assertIsInstance(rs, PeriodIndex) def test_constructor_simple_new(self): @@ -789,7 +789,7 @@ def _check(op): index_result = op(index, element) self.assertIsInstance(index_result, np.ndarray) - self.assert_numpy_array_equal(arr_result, index_result) + tm.assert_numpy_array_equal(arr_result, index_result) _check(operator.eq) _check(operator.ne) @@ -847,10 +847,10 @@ def test_shift(self): self.assertIs(shifted, self.dateIndex) shifted = self.dateIndex.shift(5, timedelta(1)) - self.assert_numpy_array_equal(shifted, self.dateIndex + timedelta(5)) + tm.assert_numpy_array_equal(shifted, self.dateIndex + timedelta(5)) shifted = self.dateIndex.shift(1, 'B') - self.assert_numpy_array_equal(shifted, self.dateIndex + offsets.BDay()) + tm.assert_numpy_array_equal(shifted, self.dateIndex + offsets.BDay()) shifted.name = 'shifted' self.assertEqual(shifted.name, shifted.shift(1, 'D').name) @@ -1203,11 +1203,11 @@ def test_get_indexer_nearest(self): all_methods = ['pad', 'backfill', 'nearest'] for method in all_methods: actual = idx.get_indexer([0, 5, 9], method=method) - self.assert_numpy_array_equivalent(actual, [0, 5, 9]) + tm.assert_numpy_array_equal(actual, [0, 5, 9]) for method, expected in zip(all_methods, [[0, 1, 8], [1, 2, 9], [0, 2, 9]]): actual = idx.get_indexer([0.2, 1.8, 8.5], method=method) - self.assert_numpy_array_equivalent(actual, expected) + tm.assert_numpy_array_equal(actual, expected) with tm.assertRaisesRegexp(ValueError, 'limit argument'): idx.get_indexer([1, 0], method='nearest', limit=1) @@ -1218,22 +1218,22 @@ def test_get_indexer_nearest_decreasing(self): all_methods = ['pad', 'backfill', 'nearest'] for method in all_methods: actual = idx.get_indexer([0, 5, 9], method=method) - self.assert_numpy_array_equivalent(actual, [9, 4, 0]) + tm.assert_numpy_array_equal(actual, [9, 4, 0]) for method, expected in zip(all_methods, [[8, 7, 0], [9, 8, 1], [9, 7, 0]]): actual = idx.get_indexer([0.2, 1.8, 8.5], method=method) - self.assert_numpy_array_equivalent(actual, expected) + tm.assert_numpy_array_equal(actual, expected) def test_get_indexer_strings(self): idx = pd.Index(['b', 'c']) actual = idx.get_indexer(['a', 'b', 'c', 'd'], method='pad') expected = [-1, 0, 1, 1] - self.assert_numpy_array_equivalent(actual, expected) + tm.assert_numpy_array_equal(actual, expected) actual = idx.get_indexer(['a', 'b', 'c', 'd'], method='backfill') expected = [0, 0, 1, -1] - self.assert_numpy_array_equivalent(actual, expected) + tm.assert_numpy_array_equal(actual, expected) with tm.assertRaises(TypeError): idx.get_indexer(['a', 'b', 'c', 'd'], method='nearest') @@ -1432,7 +1432,7 @@ def test_isin(self): idx = Index(['qux', 'baz', 'foo', 'bar']) result = idx.isin(values) expected = np.array([False, False, True, True]) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) # empty, return dtype bool idx = Index([]) @@ -1441,20 +1441,20 @@ def test_isin(self): self.assertEqual(result.dtype, np.bool_) def test_isin_nan(self): - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Index(['a', np.nan]).isin([np.nan]), [False, True]) - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Index(['a', pd.NaT]).isin([pd.NaT]), [False, True]) - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Index(['a', np.nan]).isin([float('nan')]), [False, False]) - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Index(['a', np.nan]).isin([pd.NaT]), [False, False]) # Float64Index overrides isin, so must be checked separately - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Float64Index([1.0, np.nan]).isin([np.nan]), [False, True]) - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Float64Index([1.0, np.nan]).isin([float('nan')]), [False, True]) - self.assert_numpy_array_equal( + tm.assert_numpy_array_equal( Float64Index([1.0, np.nan]).isin([pd.NaT]), [False, True]) def test_isin_level_kwarg(self): @@ -1462,8 +1462,8 @@ def check_idx(idx): values = idx.tolist()[-2:] + ['nonexisting'] expected = np.array([False, False, True, True]) - self.assert_numpy_array_equal(expected, idx.isin(values, level=0)) - self.assert_numpy_array_equal(expected, idx.isin(values, level=-1)) + tm.assert_numpy_array_equal(expected, idx.isin(values, level=0)) + tm.assert_numpy_array_equal(expected, idx.isin(values, level=-1)) self.assertRaises(IndexError, idx.isin, values, level=1) self.assertRaises(IndexError, idx.isin, values, level=10) @@ -1473,7 +1473,7 @@ def check_idx(idx): self.assertRaises(KeyError, idx.isin, values, level='foobar') idx.name = 'foobar' - self.assert_numpy_array_equal(expected, + tm.assert_numpy_array_equal(expected, idx.isin(values, level='foobar')) self.assertRaises(KeyError, idx.isin, values, level='xyzzy') @@ -1489,7 +1489,7 @@ def test_boolean_cmp(self): idx = Index(values) res = (idx == values) - self.assert_numpy_array_equal(res,np.array([True,True,True,True],dtype=bool)) + tm.assert_numpy_array_equal(res,np.array([True,True,True,True],dtype=bool)) def test_get_level_values(self): result = self.strIndex.get_level_values(0) @@ -1539,7 +1539,7 @@ def test_str_attribute(self): # test boolean case, should return np.array instead of boolean Index idx = Index(['a1', 'a2', 'b1', 'b2']) expected = np.array([True, True, False, False]) - self.assert_numpy_array_equivalent(idx.str.startswith('a'), expected) + tm.assert_numpy_array_equal(idx.str.startswith('a'), expected) self.assertIsInstance(idx.str.startswith('a'), np.ndarray) s = Series(range(4), index=idx) expected = Series(range(2), index=['a1', 'a2']) @@ -1646,12 +1646,12 @@ def test_equals_op_multiindex(self): # test comparisons of multiindex from pandas.compat import StringIO df = pd.read_csv(StringIO('a,b,c\n1,2,3\n4,5,6'), index_col=[0, 1]) - assert_numpy_array_equivalent(df.index == df.index, np.array([True, True])) + tm.assert_numpy_array_equal(df.index == df.index, np.array([True, True])) mi1 = MultiIndex.from_tuples([(1, 2), (4, 5)]) - assert_numpy_array_equivalent(df.index == mi1, np.array([True, True])) + tm.assert_numpy_array_equal(df.index == mi1, np.array([True, True])) mi2 = MultiIndex.from_tuples([(1, 2), (4, 6)]) - assert_numpy_array_equivalent(df.index == mi2, np.array([True, False])) + tm.assert_numpy_array_equal(df.index == mi2, np.array([True, False])) mi3 = MultiIndex.from_tuples([(1, 2), (4, 5), (8, 9)]) with tm.assertRaisesRegexp(ValueError, "Lengths must match"): df.index == mi3 @@ -1659,7 +1659,8 @@ def test_equals_op_multiindex(self): index_a = Index(['foo', 'bar', 'baz']) with tm.assertRaisesRegexp(ValueError, "Lengths must match"): df.index == index_a - assert_numpy_array_equivalent(index_a == mi3, np.array([False, False, False])) + tm.assert_numpy_array_equal(index_a == mi3, np.array([False, False, False])) + class TestCategoricalIndex(Base, tm.TestCase): _holder = CategoricalIndex @@ -1689,39 +1690,39 @@ def test_construction(self): # empty result = CategoricalIndex(categories=categories) self.assertTrue(result.categories.equals(Index(categories))) - self.assert_numpy_array_equal(result.codes,np.array([],dtype='int8')) + tm.assert_numpy_array_equal(result.codes, np.array([],dtype='int8')) self.assertFalse(result.ordered) # passing categories result = CategoricalIndex(list('aabbca'),categories=categories) self.assertTrue(result.categories.equals(Index(categories))) - self.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) + tm.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) c = pd.Categorical(list('aabbca')) result = CategoricalIndex(c) self.assertTrue(result.categories.equals(Index(list('abc')))) - self.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) + tm.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) self.assertFalse(result.ordered) result = CategoricalIndex(c,categories=categories) self.assertTrue(result.categories.equals(Index(categories))) - self.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) + tm.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) self.assertFalse(result.ordered) ci = CategoricalIndex(c,categories=list('abcd')) result = CategoricalIndex(ci) self.assertTrue(result.categories.equals(Index(categories))) - self.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) + tm.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,2,0],dtype='int8')) self.assertFalse(result.ordered) result = CategoricalIndex(ci, categories=list('ab')) self.assertTrue(result.categories.equals(Index(list('ab')))) - self.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,-1,0],dtype='int8')) + tm.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,-1,0],dtype='int8')) self.assertFalse(result.ordered) result = CategoricalIndex(ci, categories=list('ab'), ordered=True) self.assertTrue(result.categories.equals(Index(list('ab')))) - self.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,-1,0],dtype='int8')) + tm.assert_numpy_array_equal(result.codes,np.array([0,0,1,1,-1,0],dtype='int8')) self.assertTrue(result.ordered) # turn me to an Index @@ -1914,7 +1915,7 @@ def test_reindex_base(self): expected = np.array([4,0,1,5,2,3]) actual = idx.get_indexer(idx) - assert_numpy_array_equivalent(expected, actual) + tm.assert_numpy_array_equal(expected, actual) with tm.assertRaisesRegexp(ValueError, 'Invalid fill method'): idx.get_indexer(idx, method='invalid') @@ -1929,7 +1930,7 @@ def test_reindexing(self): expected = oidx.get_indexer_non_unique(finder)[0] actual = ci.get_indexer(finder) - assert_numpy_array_equivalent(expected, actual) + tm.assert_numpy_array_equal(expected, actual) def test_duplicates(self): @@ -1976,13 +1977,13 @@ def test_repr_roundtrip(self): def test_isin(self): ci = CategoricalIndex(list('aabca') + [np.nan],categories=['c','a','b',np.nan]) - self.assert_numpy_array_equal(ci.isin(['c']),np.array([False,False,False,True,False,False])) - self.assert_numpy_array_equal(ci.isin(['c','a','b']),np.array([True]*5 + [False])) - self.assert_numpy_array_equal(ci.isin(['c','a','b',np.nan]),np.array([True]*6)) + tm.assert_numpy_array_equal(ci.isin(['c']),np.array([False,False,False,True,False,False])) + tm.assert_numpy_array_equal(ci.isin(['c','a','b']),np.array([True]*5 + [False])) + tm.assert_numpy_array_equal(ci.isin(['c','a','b',np.nan]),np.array([True]*6)) # mismatched categorical -> coerced to ndarray so doesn't matter - self.assert_numpy_array_equal(ci.isin(ci.set_categories(list('abcdefghi'))),np.array([True]*6)) - self.assert_numpy_array_equal(ci.isin(ci.set_categories(list('defghi'))),np.array([False]*5 + [True])) + tm.assert_numpy_array_equal(ci.isin(ci.set_categories(list('abcdefghi'))),np.array([True]*6)) + tm.assert_numpy_array_equal(ci.isin(ci.set_categories(list('defghi'))),np.array([False]*5 + [True])) def test_identical(self): @@ -2231,12 +2232,12 @@ def test_equals(self): def test_get_indexer(self): idx = Float64Index([0.0, 1.0, 2.0]) - self.assert_numpy_array_equivalent(idx.get_indexer(idx), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(idx), [0, 1, 2]) target = [-0.1, 0.5, 1.1] - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'pad'), [-1, 0, 1]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'backfill'), [0, 1, 2]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'nearest'), [0, 1, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'pad'), [-1, 0, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'backfill'), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'nearest'), [0, 1, 1]) def test_get_loc(self): idx = Float64Index([0.0, 1.0, 2.0]) @@ -2274,16 +2275,16 @@ def test_doesnt_contain_all_the_things(self): def test_nan_multiple_containment(self): i = Float64Index([1.0, np.nan]) - assert_numpy_array_equivalent(i.isin([1.0]), np.array([True, False])) - assert_numpy_array_equivalent(i.isin([2.0, np.pi]), - np.array([False, False])) - assert_numpy_array_equivalent(i.isin([np.nan]), - np.array([False, True])) - assert_numpy_array_equivalent(i.isin([1.0, np.nan]), - np.array([True, True])) + tm.assert_numpy_array_equal(i.isin([1.0]), np.array([True, False])) + tm.assert_numpy_array_equal(i.isin([2.0, np.pi]), + np.array([False, False])) + tm.assert_numpy_array_equal(i.isin([np.nan]), + np.array([False, True])) + tm.assert_numpy_array_equal(i.isin([1.0, np.nan]), + np.array([True, True])) i = Float64Index([1.0, 2.0]) - assert_numpy_array_equivalent(i.isin([np.nan]), - np.array([False, False])) + tm.assert_numpy_array_equal(i.isin([np.nan]), + np.array([False, False])) def test_astype_from_object(self): index = Index([1.0, np.nan, 0.2], dtype='object') @@ -2313,11 +2314,11 @@ def test_constructor(self): # pass list, coerce fine index = Int64Index([-5, 0, 1, 2]) expected = np.array([-5, 0, 1, 2], dtype=np.int64) - self.assert_numpy_array_equal(index, expected) + tm.assert_numpy_array_equal(index, expected) # from iterable index = Int64Index(iter([-5, 0, 1, 2])) - self.assert_numpy_array_equal(index, expected) + tm.assert_numpy_array_equal(index, expected) # scalar raise Exception self.assertRaises(TypeError, Int64Index, 5) @@ -2325,7 +2326,7 @@ def test_constructor(self): # copy arr = self.index.values new_index = Int64Index(arr, copy=True) - self.assert_numpy_array_equal(new_index, self.index) + tm.assert_numpy_array_equal(new_index, self.index) val = arr[0] + 3000 # this should not change index arr[0] = val @@ -2438,19 +2439,19 @@ def test_get_indexer(self): target = Int64Index(np.arange(10)) indexer = self.index.get_indexer(target) expected = np.array([0, -1, 1, -1, 2, -1, 3, -1, 4, -1]) - self.assert_numpy_array_equal(indexer, expected) + tm.assert_numpy_array_equal(indexer, expected) def test_get_indexer_pad(self): target = Int64Index(np.arange(10)) indexer = self.index.get_indexer(target, method='pad') expected = np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4]) - self.assert_numpy_array_equal(indexer, expected) + tm.assert_numpy_array_equal(indexer, expected) def test_get_indexer_backfill(self): target = Int64Index(np.arange(10)) indexer = self.index.get_indexer(target, method='backfill') expected = np.array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5]) - self.assert_numpy_array_equal(indexer, expected) + tm.assert_numpy_array_equal(indexer, expected) def test_join_outer(self): other = Int64Index([7, 12, 25, 1, 2, 5]) @@ -2471,8 +2472,8 @@ def test_join_outer(self): tm.assertIsInstance(res, Int64Index) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(ridx, eridx) # monotonic res, lidx, ridx = self.index.join(other_mono, how='outer', @@ -2484,8 +2485,8 @@ def test_join_outer(self): dtype=np.int64) tm.assertIsInstance(res, Int64Index) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(ridx, eridx) def test_join_inner(self): other = Int64Index([7, 12, 25, 1, 2, 5]) @@ -2507,8 +2508,8 @@ def test_join_inner(self): tm.assertIsInstance(res, Int64Index) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(ridx, eridx) # monotonic res, lidx, ridx = self.index.join(other_mono, how='inner', @@ -2520,8 +2521,8 @@ def test_join_inner(self): eridx = np.array([1, 4]) tm.assertIsInstance(res, Int64Index) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(ridx, eridx) def test_join_left(self): other = Int64Index([7, 12, 25, 1, 2, 5]) @@ -2537,7 +2538,7 @@ def test_join_left(self): tm.assertIsInstance(res, Int64Index) self.assertTrue(res.equals(eres)) self.assertIsNone(lidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(ridx, eridx) # monotonic res, lidx, ridx = self.index.join(other_mono, how='left', @@ -2547,7 +2548,7 @@ def test_join_left(self): tm.assertIsInstance(res, Int64Index) self.assertTrue(res.equals(eres)) self.assertIsNone(lidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(ridx, eridx) # non-unique """ @@ -2558,8 +2559,8 @@ def test_join_left(self): eridx = np.array([0, 2, 3, -1, -1]) elidx = np.array([0, 1, 2, 3, 4]) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(ridx, eridx) """ def test_join_right(self): @@ -2575,7 +2576,7 @@ def test_join_right(self): tm.assertIsInstance(other, Int64Index) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(lidx, elidx) self.assertIsNone(ridx) # monotonic @@ -2586,7 +2587,7 @@ def test_join_right(self): dtype=np.int64) tm.assertIsInstance(other, Int64Index) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(lidx, elidx) self.assertIsNone(ridx) # non-unique @@ -2598,8 +2599,8 @@ def test_join_right(self): elidx = np.array([0, 2, 3, -1, -1]) eridx = np.array([0, 1, 2, 3, 4]) self.assertTrue(res.equals(eres)) - self.assert_numpy_array_equal(lidx, elidx) - self.assert_numpy_array_equal(ridx, eridx) + tm.assert_numpy_array_equal(lidx, elidx) + tm.assert_numpy_array_equal(ridx, eridx) idx = Index([1,1,2,5]) idx2 = Index([1,2,5,9,7]) @@ -2645,10 +2646,10 @@ def test_join_non_unique(self): self.assertTrue(joined.equals(exp_joined)) exp_lidx = np.array([2, 2, 3, 3, 0, 0, 1, 1], dtype=np.int64) - self.assert_numpy_array_equal(lidx, exp_lidx) + tm.assert_numpy_array_equal(lidx, exp_lidx) exp_ridx = np.array([2, 3, 2, 3, 0, 1, 0, 1], dtype=np.int64) - self.assert_numpy_array_equal(ridx, exp_ridx) + tm.assert_numpy_array_equal(ridx, exp_ridx) def test_join_self(self): kinds = 'outer', 'inner', 'left', 'right' @@ -2660,12 +2661,12 @@ def test_intersection(self): other = Index([1, 2, 3, 4, 5]) result = self.index.intersection(other) expected = np.sort(np.intersect1d(self.index.values, other.values)) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) result = other.intersection(self.index) expected = np.sort(np.asarray(np.intersect1d(self.index.values, other.values))) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) def test_intersect_str_dates(self): dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)] @@ -2683,11 +2684,11 @@ def test_union_noncomparable(self): other = Index([now + timedelta(i) for i in range(4)], dtype=object) result = self.index.union(other) expected = np.concatenate((self.index, other)) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) result = other.union(self.index) expected = np.concatenate((other, self.index)) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) def test_cant_or_shouldnt_cast(self): # can't @@ -2831,19 +2832,19 @@ def test_get_loc(self): # time indexing idx = pd.date_range('2000-01-01', periods=24, freq='H') - assert_numpy_array_equivalent(idx.get_loc(time(12)), [12]) - assert_numpy_array_equivalent(idx.get_loc(time(12, 30)), []) + tm.assert_numpy_array_equal(idx.get_loc(time(12)), [12]) + tm.assert_numpy_array_equal(idx.get_loc(time(12, 30)), []) with tm.assertRaises(NotImplementedError): idx.get_loc(time(12, 30), method='pad') def test_get_indexer(self): idx = pd.date_range('2000-01-01', periods=3) - self.assert_numpy_array_equivalent(idx.get_indexer(idx), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(idx), [0, 1, 2]) target = idx[0] + pd.to_timedelta(['-1 hour', '12 hours', '1 day 1 hour']) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'pad'), [-1, 0, 1]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'backfill'), [0, 1, 2]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'nearest'), [0, 1, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'pad'), [-1, 0, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'backfill'), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'nearest'), [0, 1, 1]) def test_roundtrip_pickle_with_tz(self): @@ -2873,7 +2874,7 @@ def test_time_loc(self): # GH8667 ts = pd.Series(np.random.randn(n), index=idx) i = np.arange(start, n, step) - tm.assert_numpy_array_equivalent(ts.index.get_loc(key), i) + tm.assert_numpy_array_equal(ts.index.get_loc(key), i) tm.assert_series_equal(ts[key], ts.iloc[i]) left, right = ts.copy(), ts.copy() @@ -2956,13 +2957,13 @@ def test_get_loc(self): def test_get_indexer(self): idx = pd.period_range('2000-01-01', periods=3).asfreq('H', how='start') - self.assert_numpy_array_equivalent(idx.get_indexer(idx), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(idx), [0, 1, 2]) target = pd.PeriodIndex(['1999-12-31T23', '2000-01-01T12', '2000-01-02T01'], freq='H') - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'pad'), [-1, 0, 1]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'backfill'), [0, 1, 2]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'nearest'), [0, 1, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'pad'), [-1, 0, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'backfill'), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'nearest'), [0, 1, 1]) with self.assertRaisesRegexp(ValueError, 'different freq'): idx.asfreq('D').get_indexer(idx) @@ -3000,12 +3001,12 @@ def test_get_loc(self): def test_get_indexer(self): idx = pd.to_timedelta(['0 days', '1 days', '2 days']) - self.assert_numpy_array_equivalent(idx.get_indexer(idx), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(idx), [0, 1, 2]) target = pd.to_timedelta(['-1 hour', '12 hours', '1 day 1 hour']) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'pad'), [-1, 0, 1]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'backfill'), [0, 1, 2]) - self.assert_numpy_array_equivalent(idx.get_indexer(target, 'nearest'), [0, 1, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'pad'), [-1, 0, 1]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'backfill'), [0, 1, 2]) + tm.assert_numpy_array_equal(idx.get_indexer(target, 'nearest'), [0, 1, 1]) def test_numeric_compat(self): @@ -3585,7 +3586,7 @@ def test_from_product(self): ('buz', 'a'), ('buz', 'b'), ('buz', 'c')] expected = MultiIndex.from_tuples(tuples, names=names) - assert_numpy_array_equivalent(result, expected) + tm.assert_numpy_array_equal(result, expected) self.assertEqual(result.names, names) def test_from_product_datetimeindex(self): @@ -3595,7 +3596,7 @@ def test_from_product_datetimeindex(self): (1, pd.Timestamp('2000-01-02')), (2, pd.Timestamp('2000-01-01')), (2, pd.Timestamp('2000-01-02'))]) - assert_numpy_array_equivalent(mi.values, etalon) + tm.assert_numpy_array_equal(mi.values, etalon) def test_values_boxed(self): tuples = [(1, pd.Timestamp('2000-01-01')), @@ -3605,9 +3606,9 @@ def test_values_boxed(self): (2, pd.Timestamp('2000-01-02')), (3, pd.Timestamp('2000-01-03'))] mi = pd.MultiIndex.from_tuples(tuples) - assert_numpy_array_equivalent(mi.values, pd.lib.list_to_object_array(tuples)) + tm.assert_numpy_array_equal(mi.values, pd.lib.list_to_object_array(tuples)) # Check that code branches for boxed values produce identical results - assert_numpy_array_equivalent(mi.values[:4], mi[:4].values) + tm.assert_numpy_array_equal(mi.values[:4], mi[:4].values) def test_append(self): result = self.index[:3].append(self.index[3:]) @@ -3624,13 +3625,13 @@ def test_append(self): def test_get_level_values(self): result = self.index.get_level_values(0) expected = ['foo', 'foo', 'bar', 'baz', 'qux', 'qux'] - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) self.assertEqual(result.name, 'first') result = self.index.get_level_values('first') expected = self.index.get_level_values(0) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) # GH 10460 index = MultiIndex(levels=[CategoricalIndex(['A', 'B']), @@ -3647,28 +3648,28 @@ def test_get_level_values_na(self): index = pd.MultiIndex.from_arrays(arrays) values = index.get_level_values(1) expected = [1, np.nan, 2] - assert_numpy_array_equivalent(values.values.astype(float), expected) + tm.assert_numpy_array_equal(values.values.astype(float), expected) arrays = [['a', 'b', 'b'], [np.nan, np.nan, 2]] index = pd.MultiIndex.from_arrays(arrays) values = index.get_level_values(1) expected = [np.nan, np.nan, 2] - assert_numpy_array_equivalent(values.values.astype(float), expected) + tm.assert_numpy_array_equal(values.values.astype(float), expected) arrays = [[np.nan, np.nan, np.nan], ['a', np.nan, 1]] index = pd.MultiIndex.from_arrays(arrays) values = index.get_level_values(0) expected = [np.nan, np.nan, np.nan] - assert_numpy_array_equivalent(values.values.astype(float), expected) + tm.assert_numpy_array_equal(values.values.astype(float), expected) values = index.get_level_values(1) expected = np.array(['a', np.nan, 1],dtype=object) - assert_numpy_array_equivalent(values.values, expected) + tm.assert_numpy_array_equal(values.values, expected) arrays = [['a', 'b', 'b'], pd.DatetimeIndex([0, 1, pd.NaT])] index = pd.MultiIndex.from_arrays(arrays) values = index.get_level_values(1) expected = pd.DatetimeIndex([0, 1, pd.NaT]) - assert_numpy_array_equivalent(values.values, expected.values) + tm.assert_numpy_array_equal(values.values, expected.values) arrays = [[], []] index = pd.MultiIndex.from_arrays(arrays) @@ -4318,7 +4319,7 @@ def test_from_tuples(self): def test_argsort(self): result = self.index.argsort() expected = self.index._tuple_index.argsort() - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) def test_sortlevel(self): import random @@ -4464,9 +4465,9 @@ def test_insert(self): # key not contained in all levels new_index = self.index.insert(0, ('abc', 'three')) - self.assert_numpy_array_equal(new_index.levels[0], + tm.assert_numpy_array_equal(new_index.levels[0], list(self.index.levels[0]) + ['abc']) - self.assert_numpy_array_equal(new_index.levels[1], + tm.assert_numpy_array_equal(new_index.levels[1], list(self.index.levels[1]) + ['three']) self.assertEqual(new_index[0], ('abc', 'three')) @@ -4542,7 +4543,7 @@ def _check_how(other, how): mask = np.array( [x[1] in exp_level for x in self.index], dtype=bool) exp_values = self.index.values[mask] - self.assert_numpy_array_equal(join_index.values, exp_values) + tm.assert_numpy_array_equal(join_index.values, exp_values) if how in ('outer', 'inner'): join_index2, ridx2, lidx2 = \ @@ -4550,9 +4551,9 @@ def _check_how(other, how): return_indexers=True) self.assertTrue(join_index.equals(join_index2)) - self.assert_numpy_array_equal(lidx, lidx2) - self.assert_numpy_array_equal(ridx, ridx2) - self.assert_numpy_array_equal(join_index2.values, exp_values) + tm.assert_numpy_array_equal(lidx, lidx2) + tm.assert_numpy_array_equal(ridx, ridx2) + tm.assert_numpy_array_equal(join_index2.values, exp_values) def _check_all(other): _check_how(other, 'outer') @@ -4600,11 +4601,11 @@ def test_reindex_level(self): self.assertTrue(target.equals(exp_index)) exp_indexer = np.array([0, 2, 4]) - self.assert_numpy_array_equal(indexer, exp_indexer) + tm.assert_numpy_array_equal(indexer, exp_indexer) self.assertTrue(target2.equals(exp_index2)) exp_indexer2 = np.array([0, -1, 0, -1, 0, -1]) - self.assert_numpy_array_equal(indexer2, exp_indexer2) + tm.assert_numpy_array_equal(indexer2, exp_indexer2) assertRaisesRegexp(TypeError, "Fill method not supported", self.index.reindex, self.index, method='pad', @@ -4694,14 +4695,14 @@ def check(nlevels, with_nulls): for take_last in [False, True]: left = mi.duplicated(take_last=take_last) right = pd.lib.duplicated(mi.values, take_last=take_last) - tm.assert_numpy_array_equivalent(left, right) + tm.assert_numpy_array_equal(left, right) # GH5873 for a in [101, 102]: mi = MultiIndex.from_arrays([[101, a], [3.5, np.nan]]) self.assertFalse(mi.has_duplicates) self.assertEqual(mi.get_duplicates(), []) - self.assert_numpy_array_equivalent(mi.duplicated(), np.zeros(2, dtype='bool')) + tm.assert_numpy_array_equal(mi.duplicated(), np.zeros(2, dtype='bool')) for n in range(1, 6): # 1st level shape for m in range(1, 5): # 2nd level shape @@ -4712,8 +4713,8 @@ def check(nlevels, with_nulls): self.assertEqual(len(mi), (n + 1) * (m + 1)) self.assertFalse(mi.has_duplicates) self.assertEqual(mi.get_duplicates(), []) - self.assert_numpy_array_equivalent(mi.duplicated(), - np.zeros(len(mi), dtype='bool')) + tm.assert_numpy_array_equal(mi.duplicated(), + np.zeros(len(mi), dtype='bool')) def test_duplicate_meta_data(self): # GH 10115 @@ -4807,7 +4808,7 @@ def test_isin(self): np.arange(4)]) result = idx.isin(values) expected = np.array([False, False, True, True]) - self.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) # empty, return dtype bool idx = MultiIndex.from_arrays([[], []]) @@ -4817,9 +4818,9 @@ def test_isin(self): def test_isin_nan(self): idx = MultiIndex.from_arrays([['foo', 'bar'], [1.0, np.nan]]) - self.assert_numpy_array_equal(idx.isin([('bar', np.nan)]), + tm.assert_numpy_array_equal(idx.isin([('bar', np.nan)]), [False, False]) - self.assert_numpy_array_equal(idx.isin([('bar', float('nan'))]), + tm.assert_numpy_array_equal(idx.isin([('bar', float('nan'))]), [False, False]) def test_isin_level_kwarg(self): @@ -4830,11 +4831,11 @@ def test_isin_level_kwarg(self): vals_1 = [2, 3, 10] expected = np.array([False, False, True, True]) - self.assert_numpy_array_equal(expected, idx.isin(vals_0, level=0)) - self.assert_numpy_array_equal(expected, idx.isin(vals_0, level=-2)) + tm.assert_numpy_array_equal(expected, idx.isin(vals_0, level=0)) + tm.assert_numpy_array_equal(expected, idx.isin(vals_0, level=-2)) - self.assert_numpy_array_equal(expected, idx.isin(vals_1, level=1)) - self.assert_numpy_array_equal(expected, idx.isin(vals_1, level=-1)) + tm.assert_numpy_array_equal(expected, idx.isin(vals_1, level=1)) + tm.assert_numpy_array_equal(expected, idx.isin(vals_1, level=-1)) self.assertRaises(IndexError, idx.isin, vals_0, level=5) self.assertRaises(IndexError, idx.isin, vals_0, level=-5) @@ -4844,8 +4845,8 @@ def test_isin_level_kwarg(self): self.assertRaises(KeyError, idx.isin, vals_1, level='A') idx.names = ['A', 'B'] - self.assert_numpy_array_equal(expected, idx.isin(vals_0, level='A')) - self.assert_numpy_array_equal(expected, idx.isin(vals_1, level='B')) + tm.assert_numpy_array_equal(expected, idx.isin(vals_0, level='A')) + tm.assert_numpy_array_equal(expected, idx.isin(vals_1, level='B')) self.assertRaises(KeyError, idx.isin, vals_1, level='C') @@ -4916,6 +4917,7 @@ def test_equals_operator(self): # GH9785 self.assertTrue((self.index == self.index).all()) + def test_get_combined_index(): from pandas.core.index import _get_combined_index result = _get_combined_index([]) diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 624fa11ac908a..d8fde1c2eaa98 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -813,7 +813,7 @@ def test_chained_getitem_with_lists(self): # GH6394 # Regression in chained getitem indexing with embedded list-like from 0.12 def check(result, expected): - self.assert_numpy_array_equal(result,expected) + tm.assert_numpy_array_equal(result,expected) tm.assertIsInstance(result, np.ndarray) @@ -4765,7 +4765,7 @@ def test_coercion_with_setitem(self): expected_series = Series(expected_result) assert_attr_equal('dtype', start_series, expected_series) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_series.values, expected_series.values, strict_nan=True) @@ -4777,7 +4777,7 @@ def test_coercion_with_loc_setitem(self): expected_series = Series(expected_result) assert_attr_equal('dtype', start_series, expected_series) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_series.values, expected_series.values, strict_nan=True) @@ -4789,7 +4789,7 @@ def test_coercion_with_setitem_and_series(self): expected_series = Series(expected_result) assert_attr_equal('dtype', start_series, expected_series) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_series.values, expected_series.values, strict_nan=True) @@ -4801,7 +4801,7 @@ def test_coercion_with_loc_and_series(self): expected_series = Series(expected_result) assert_attr_equal('dtype', start_series, expected_series) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_series.values, expected_series.values, strict_nan=True) @@ -4828,7 +4828,7 @@ def test_coercion_with_loc(self): expected_dataframe = DataFrame({'foo': expected_result}) assert_attr_equal('dtype', start_dataframe['foo'], expected_dataframe['foo']) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_dataframe['foo'].values, expected_dataframe['foo'].values, strict_nan=True) @@ -4840,7 +4840,7 @@ def test_coercion_with_setitem_and_dataframe(self): expected_dataframe = DataFrame({'foo': expected_result}) assert_attr_equal('dtype', start_dataframe['foo'], expected_dataframe['foo']) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_dataframe['foo'].values, expected_dataframe['foo'].values, strict_nan=True) @@ -4852,7 +4852,7 @@ def test_none_coercion_loc_and_dataframe(self): expected_dataframe = DataFrame({'foo': expected_result}) assert_attr_equal('dtype', start_dataframe['foo'], expected_dataframe['foo']) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_dataframe['foo'].values, expected_dataframe['foo'].values, strict_nan=True) @@ -4872,7 +4872,7 @@ def test_none_coercion_mixed_dtypes(self): for column in expected_dataframe.columns: assert_attr_equal('dtype', start_dataframe[column], expected_dataframe[column]) - self.assert_numpy_array_equivalent( + tm.assert_numpy_array_equal( start_dataframe[column].values, expected_dataframe[column].values, strict_nan=True) diff --git a/pandas/tests/test_internals.py b/pandas/tests/test_internals.py index 5a1eb719270c4..7c51641b8e5da 100644 --- a/pandas/tests/test_internals.py +++ b/pandas/tests/test_internals.py @@ -658,7 +658,9 @@ def test_interleave_non_unique_cols(self): df_unique = df.copy() df_unique.columns = ['x', 'y'] - np.testing.assert_array_equal(df_unique.values, df.values) + self.assertEqual(df_unique.values.shape, df.values.shape) + tm.assert_numpy_array_equal(df_unique.values[0], df.values[0]) + tm.assert_numpy_array_equal(df_unique.values[1], df.values[1]) def test_consolidate(self): pass @@ -1066,7 +1068,7 @@ def test_slice_iter(self): def test_slice_to_array_conversion(self): def assert_as_array_equals(slc, asarray): - np.testing.assert_array_equal( + tm.assert_numpy_array_equal( BlockPlacement(slc).as_array, np.asarray(asarray)) diff --git a/pandas/tests/test_reshape.py b/pandas/tests/test_reshape.py index f1670ce885d6c..2961301366188 100644 --- a/pandas/tests/test_reshape.py +++ b/pandas/tests/test_reshape.py @@ -15,7 +15,6 @@ import numpy as np from pandas.util.testing import assert_frame_equal -from numpy.testing import assert_array_equal from pandas.core.reshape import (melt, lreshape, get_dummies, wide_to_long) @@ -234,7 +233,7 @@ def test_include_na(self): res_just_na = get_dummies([nan], dummy_na=True, sparse=self.sparse) exp_just_na = DataFrame(Series(1.0,index=[0]),columns=[nan]) - assert_array_equal(res_just_na.values, exp_just_na.values) + tm.assert_numpy_array_equal(res_just_na.values, exp_just_na.values) def test_unicode(self): # See GH 6885 - get_dummies chokes on unicode values import unicodedata diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index cb6659af9eca5..4beba4ee3751c 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -1562,7 +1562,7 @@ def test_reshape_non_2d(self): a = Series([1, 2, 3, 4]) result = a.reshape(2, 2) expected = a.values.reshape(2, 2) - np.testing.assert_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) self.assertTrue(type(result) is type(expected)) def test_reshape_2d_return_array(self): @@ -7070,13 +7070,13 @@ def test_searchsorted_numeric_dtypes_scalar(self): r = s.searchsorted([30]) e = np.array([2]) - tm.assert_array_equal(r, e) + tm.assert_numpy_array_equal(r, e) def test_searchsorted_numeric_dtypes_vector(self): s = Series([1, 2, 90, 1000, 3e9]) r = s.searchsorted([91, 2e6]) e = np.array([3, 4]) - tm.assert_array_equal(r, e) + tm.assert_numpy_array_equal(r, e) def test_search_sorted_datetime64_scalar(self): s = Series(pd.date_range('20120101', periods=10, freq='2D')) @@ -7090,14 +7090,14 @@ def test_search_sorted_datetime64_list(self): v = [pd.Timestamp('20120102'), pd.Timestamp('20120104')] r = s.searchsorted(v) e = np.array([1, 2]) - tm.assert_array_equal(r, e) + tm.assert_numpy_array_equal(r, e) def test_searchsorted_sorter(self): # GH8490 s = Series([3, 1, 2]) r = s.searchsorted([0, 3], sorter=np.argsort(s)) e = np.array([0, 2]) - tm.assert_array_equal(r, e) + tm.assert_numpy_array_equal(r, e) def test_to_frame_expanddim(self): # GH 9762 diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index facbd57512257..6a9ad175f42dd 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -11,7 +11,6 @@ from numpy import nan as NA import numpy as np -from numpy.testing import assert_array_equal from numpy.random import randint from pandas.compat import range, lrange, u, unichr @@ -53,7 +52,7 @@ def test_iter(self): # indices of each yielded Series should be equal to the index of # the original Series - assert_array_equal(s.index, ds.index) + tm.assert_numpy_array_equal(s.index, ds.index) for el in s: # each element of the series is either a basestring/str or nan @@ -561,7 +560,7 @@ def test_extract(self): s_or_idx = klass(['A1', 'A2']) result = s_or_idx.str.extract(r'(?PA)\d') tm.assert_equal(result.name, 'uno') - tm.assert_array_equal(result, klass(['A', 'A'])) + tm.assert_numpy_array_equal(result, klass(['A', 'A'])) s = Series(['A1', 'B2', 'C3']) # one group, no matches @@ -918,34 +917,34 @@ def test_index(self): s = klass(['ABCDEFG', 'BCDEFEF', 'DEFGHIJEF', 'EFGHEF']) result = s.str.index('EF') - tm.assert_array_equal(result, klass([4, 3, 1, 0])) + tm.assert_numpy_array_equal(result, klass([4, 3, 1, 0])) expected = np.array([v.index('EF') for v in s.values]) - tm.assert_array_equal(result.values, expected) + tm.assert_numpy_array_equal(result.values, expected) result = s.str.rindex('EF') - tm.assert_array_equal(result, klass([4, 5, 7, 4])) + tm.assert_numpy_array_equal(result, klass([4, 5, 7, 4])) expected = np.array([v.rindex('EF') for v in s.values]) - tm.assert_array_equal(result.values, expected) + tm.assert_numpy_array_equal(result.values, expected) result = s.str.index('EF', 3) - tm.assert_array_equal(result, klass([4, 3, 7, 4])) + tm.assert_numpy_array_equal(result, klass([4, 3, 7, 4])) expected = np.array([v.index('EF', 3) for v in s.values]) - tm.assert_array_equal(result.values, expected) + tm.assert_numpy_array_equal(result.values, expected) result = s.str.rindex('EF', 3) - tm.assert_array_equal(result, klass([4, 5, 7, 4])) + tm.assert_numpy_array_equal(result, klass([4, 5, 7, 4])) expected = np.array([v.rindex('EF', 3) for v in s.values]) - tm.assert_array_equal(result.values, expected) + tm.assert_numpy_array_equal(result.values, expected) result = s.str.index('E', 4, 8) - tm.assert_array_equal(result, klass([4, 5, 7, 4])) + tm.assert_numpy_array_equal(result, klass([4, 5, 7, 4])) expected = np.array([v.index('E', 4, 8) for v in s.values]) - tm.assert_array_equal(result.values, expected) + tm.assert_numpy_array_equal(result.values, expected) result = s.str.rindex('E', 0, 5) - tm.assert_array_equal(result, klass([4, 3, 1, 4])) + tm.assert_numpy_array_equal(result, klass([4, 3, 1, 4])) expected = np.array([v.rindex('E', 0, 5) for v in s.values]) - tm.assert_array_equal(result.values, expected) + tm.assert_numpy_array_equal(result.values, expected) with tm.assertRaisesRegexp(ValueError, "substring not found"): result = s.str.index('DE') @@ -956,9 +955,9 @@ def test_index(self): # test with nan s = Series(['abcb', 'ab', 'bcbe', np.nan]) result = s.str.index('b') - tm.assert_array_equal(result, Series([1, 1, 0, np.nan])) + tm.assert_numpy_array_equal(result, Series([1, 1, 0, np.nan])) result = s.str.rindex('b') - tm.assert_array_equal(result, Series([3, 1, 2, np.nan])) + tm.assert_numpy_array_equal(result, Series([3, 1, 2, np.nan])) def test_pad(self): values = Series(['a', 'b', NA, 'c', NA, 'eeeeee']) @@ -1054,17 +1053,17 @@ def test_translate(self): table = str.maketrans('abc', 'cde') result = s.str.translate(table) expected = klass(['cdedefg', 'cdee', 'edddfg', 'edefggg']) - tm.assert_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) # use of deletechars is python 2 only if not compat.PY3: result = s.str.translate(table, deletechars='fg') expected = klass(['cdede', 'cdee', 'eddd', 'ede']) - tm.assert_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) result = s.str.translate(None, deletechars='fg') expected = klass(['abcde', 'abcc', 'cddd', 'cde']) - tm.assert_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) else: with tm.assertRaisesRegexp(ValueError, "deletechars is not a valid argument"): result = s.str.translate(table, deletechars='fg') @@ -1073,7 +1072,7 @@ def test_translate(self): s = Series(['a', 'b', 'c', 1.2]) expected = Series(['c', 'd', 'e', np.nan]) result = s.str.translate(table) - tm.assert_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) def test_center_ljust_rjust(self): values = Series(['a', 'b', NA, 'c', NA, 'eeeeee']) diff --git a/pandas/tests/test_testing.py b/pandas/tests/test_testing.py index 38296e3a5ff5a..668579911d6d5 100644 --- a/pandas/tests/test_testing.py +++ b/pandas/tests/test_testing.py @@ -10,8 +10,7 @@ import pandas.util.testing as tm from pandas.util.testing import ( assert_almost_equal, assertRaisesRegexp, raise_with_traceback, - assert_series_equal, assert_frame_equal, assert_isinstance, - RNGContext + assert_series_equal, assert_frame_equal, RNGContext ) # let's get meta. @@ -259,7 +258,7 @@ def test_warning(self): self.assertNotAlmostEquals(1, 2) with tm.assert_produces_warning(FutureWarning): - assert_isinstance(Series([1, 2]), Series, msg='xxx') + tm.assert_isinstance(Series([1, 2]), Series, msg='xxx') class TestLocale(tm.TestCase): diff --git a/pandas/tools/tests/test_tile.py b/pandas/tools/tests/test_tile.py index 4a0218bef6001..eac6973bffb25 100644 --- a/pandas/tools/tests/test_tile.py +++ b/pandas/tools/tests/test_tile.py @@ -13,8 +13,6 @@ from pandas.tools.tile import cut, qcut import pandas.tools.tile as tmod -from numpy.testing import assert_equal, assert_almost_equal - class TestCut(tm.TestCase): @@ -22,31 +20,31 @@ def test_simple(self): data = np.ones(5) result = cut(data, 4, labels=False) desired = [1, 1, 1, 1, 1] - assert_equal(result, desired) + tm.assert_numpy_array_equal(result, desired) def test_bins(self): data = np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]) result, bins = cut(data, 3, retbins=True) - assert_equal(result.codes, [0, 0, 0, 1, 2, 0]) - assert_almost_equal(bins, [0.1905, 3.36666667, 6.53333333, 9.7]) + tm.assert_numpy_array_equal(result.codes, [0, 0, 0, 1, 2, 0]) + tm.assert_almost_equal(bins, [0.1905, 3.36666667, 6.53333333, 9.7]) def test_right(self): data = np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1, 2.575]) result, bins = cut(data, 4, right=True, retbins=True) - assert_equal(result.codes, [0, 0, 0, 2, 3, 0, 0]) - assert_almost_equal(bins, [0.1905, 2.575, 4.95, 7.325, 9.7]) + tm.assert_numpy_array_equal(result.codes, [0, 0, 0, 2, 3, 0, 0]) + tm.assert_almost_equal(bins, [0.1905, 2.575, 4.95, 7.325, 9.7]) def test_noright(self): data = np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1, 2.575]) result, bins = cut(data, 4, right=False, retbins=True) - assert_equal(result.codes, [0, 0, 0, 2, 3, 0, 1]) - assert_almost_equal(bins, [0.2, 2.575, 4.95, 7.325, 9.7095]) + tm.assert_numpy_array_equal(result.codes, [0, 0, 0, 2, 3, 0, 1]) + tm.assert_almost_equal(bins, [0.2, 2.575, 4.95, 7.325, 9.7095]) def test_arraylike(self): data = [.2, 1.4, 2.5, 6.2, 9.7, 2.1] result, bins = cut(data, 3, retbins=True) - assert_equal(result.codes, [0, 0, 0, 1, 2, 0]) - assert_almost_equal(bins, [0.1905, 3.36666667, 6.53333333, 9.7]) + tm.assert_numpy_array_equal(result.codes, [0, 0, 0, 1, 2, 0]) + tm.assert_almost_equal(bins, [0.1905, 3.36666667, 6.53333333, 9.7]) def test_bins_not_monotonic(self): data = [.2, 1.4, 2.5, 6.2, 9.7, 2.1] @@ -68,7 +66,7 @@ def test_cut_out_of_range_more(self): s = Series([0, -1, 0, 1, -3]) ind = cut(s, [0, 1], labels=False) exp = [np.nan, np.nan, np.nan, 0, np.nan] - assert_almost_equal(ind, exp) + tm.assert_almost_equal(ind, exp) def test_labels(self): arr = np.tile(np.arange(0, 1.01, 0.1), 4) @@ -122,8 +120,8 @@ def test_inf_handling(self): ex_categories = ['(-inf, 2]', '(2, 4]', '(4, inf]'] - np.testing.assert_array_equal(result.categories, ex_categories) - np.testing.assert_array_equal(result_ser.cat.categories, ex_categories) + tm.assert_numpy_array_equal(result.categories, ex_categories) + tm.assert_numpy_array_equal(result_ser.cat.categories, ex_categories) self.assertEqual(result[5], '(4, inf]') self.assertEqual(result[0], '(-inf, 2]') self.assertEqual(result_ser[5], '(4, inf]') @@ -134,7 +132,7 @@ def test_qcut(self): labels, bins = qcut(arr, 4, retbins=True) ex_bins = quantile(arr, [0, .25, .5, .75, 1.]) - assert_almost_equal(bins, ex_bins) + tm.assert_almost_equal(bins, ex_bins) ex_levels = cut(arr, ex_bins, include_lowest=True) self.assert_numpy_array_equal(labels, ex_levels) @@ -252,12 +250,12 @@ def test_series_retbins(self): # GH 8589 s = Series(np.arange(4)) result, bins = cut(s, 2, retbins=True) - assert_equal(result.cat.codes.values, [0, 0, 1, 1]) - assert_almost_equal(bins, [-0.003, 1.5, 3]) + tm.assert_numpy_array_equal(result.cat.codes.values, [0, 0, 1, 1]) + tm.assert_almost_equal(bins, [-0.003, 1.5, 3]) result, bins = qcut(s, 2, retbins=True) - assert_equal(result.cat.codes.values, [0, 0, 1, 1]) - assert_almost_equal(bins, [0, 1.5, 3]) + tm.assert_numpy_array_equal(result.cat.codes.values, [0, 0, 1, 1]) + tm.assert_almost_equal(bins, [0, 1.5, 3]) def curpath(): diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index a597087316f77..b9757c9e1b5d7 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -30,7 +30,6 @@ assertRaisesRegexp) import pandas.util.testing as tm from pandas import compat -from numpy.testing import assert_array_equal class TestPeriodProperties(tm.TestCase): @@ -1979,7 +1978,7 @@ def test_negative_ordinals(self): idx1 = PeriodIndex(ordinal=[-1, 0, 1], freq='A') idx2 = PeriodIndex(ordinal=np.array([-1, 0, 1]), freq='A') - assert_array_equal(idx1,idx2) + tm.assert_numpy_array_equal(idx1,idx2) def test_dti_to_period(self): dti = DatetimeIndex(start='1/1/2005', end='12/1/2005', freq='M') @@ -2393,7 +2392,7 @@ def test_map(self): result = index.map(lambda x: x.ordinal) exp = [x.ordinal for x in index] - assert_array_equal(result, exp) + tm.assert_numpy_array_equal(result, exp) def test_map_with_string_constructor(self): raw = [2005, 2007, 2009] @@ -2418,7 +2417,7 @@ def test_map_with_string_constructor(self): self.assertEqual(res.dtype, np.dtype('object').type) # lastly, values should compare equal - assert_array_equal(res, expected) + tm.assert_numpy_array_equal(res, expected) def test_convert_array_of_periods(self): rng = period_range('1/1/2000', periods=20, freq='D') diff --git a/pandas/tseries/tests/test_plotting.py b/pandas/tseries/tests/test_plotting.py index 2ba65c07aa114..11c630599e0e7 100644 --- a/pandas/tseries/tests/test_plotting.py +++ b/pandas/tseries/tests/test_plotting.py @@ -5,7 +5,6 @@ import numpy as np from numpy.testing.decorators import slow -from numpy.testing import assert_array_equal from pandas import Index, Series, DataFrame @@ -306,7 +305,7 @@ def test_dataframe(self): bts = DataFrame({'a': tm.makeTimeSeries()}) ax = bts.plot() idx = ax.get_lines()[0].get_xdata() - assert_array_equal(bts.index.to_period(), PeriodIndex(idx)) + tm.assert_numpy_array_equal(bts.index.to_period(), PeriodIndex(idx)) @slow def test_axis_limits(self): @@ -642,9 +641,9 @@ def test_mixed_freq_irregular_first(self): self.assertFalse(hasattr(ax, 'freq')) lines = ax.get_lines() x1 = lines[0].get_xdata() - assert_array_equal(x1, s2.index.asobject.values) + tm.assert_numpy_array_equal(x1, s2.index.asobject.values) x2 = lines[1].get_xdata() - assert_array_equal(x2, s1.index.asobject.values) + tm.assert_numpy_array_equal(x2, s1.index.asobject.values) def test_mixed_freq_regular_first_df(self): # GH 9852 @@ -674,9 +673,9 @@ def test_mixed_freq_irregular_first_df(self): self.assertFalse(hasattr(ax, 'freq')) lines = ax.get_lines() x1 = lines[0].get_xdata() - assert_array_equal(x1, s2.index.asobject.values) + tm.assert_numpy_array_equal(x1, s2.index.asobject.values) x2 = lines[1].get_xdata() - assert_array_equal(x2, s1.index.asobject.values) + tm.assert_numpy_array_equal(x2, s1.index.asobject.values) def test_mixed_freq_hf_first(self): idxh = date_range('1/1/1999', periods=365, freq='D') @@ -1044,7 +1043,7 @@ def test_ax_plot(self): fig = plt.figure() ax = fig.add_subplot(111) lines = ax.plot(x, y, label='Y') - assert_array_equal(DatetimeIndex(lines[0].get_xdata()), x) + tm.assert_numpy_array_equal(DatetimeIndex(lines[0].get_xdata()), x) @slow def test_mpl_nopandas(self): @@ -1063,9 +1062,9 @@ def test_mpl_nopandas(self): ax.plot_date([x.toordinal() for x in dates], values2, **kw) line1, line2 = ax.get_lines() - assert_array_equal(np.array([x.toordinal() for x in dates]), + tm.assert_numpy_array_equal(np.array([x.toordinal() for x in dates]), line1.get_xydata()[:, 0]) - assert_array_equal(np.array([x.toordinal() for x in dates]), + tm.assert_numpy_array_equal(np.array([x.toordinal() for x in dates]), line2.get_xydata()[:, 0]) @slow diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 9703accc42695..85aaf32e4dae2 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -30,7 +30,6 @@ from pandas.compat import range, long, StringIO, lrange, lmap, zip, product from numpy.random import rand -from numpy.testing import assert_array_equal from pandas.util.testing import assert_frame_equal import pandas.compat as compat import pandas.core.common as com @@ -849,11 +848,11 @@ def test_string_na_nat_conversion(self): result2 = to_datetime(strings) tm.assertIsInstance(result2, DatetimeIndex) - self.assert_numpy_array_equivalent(result, result2) + tm.assert_numpy_array_equal(result, result2) malformed = np.array(['1/100/2000', np.nan], dtype=object) result = to_datetime(malformed) - self.assert_numpy_array_equivalent(result, malformed) + tm.assert_numpy_array_equal(result, malformed) self.assertRaises(ValueError, to_datetime, malformed, errors='raise') @@ -936,7 +935,7 @@ def test_nat_vector_field_access(self): result = getattr(idx, field) expected = [getattr(x, field) if x is not NaT else np.nan for x in idx] - self.assert_numpy_array_equivalent(result, np.array(expected)) + self.assert_numpy_array_equal(result, np.array(expected)) def test_nat_scalar_field_access(self): fields = ['year', 'quarter', 'month', 'day', 'hour', @@ -2758,7 +2757,7 @@ def test_does_not_convert_mixed_integer(self): joined = cols.join(df.columns) self.assertEqual(cols.dtype, np.dtype('O')) self.assertEqual(cols.dtype, joined.dtype) - assert_array_equal(cols.values, joined.values) + tm.assert_numpy_array_equal(cols.values, joined.values) def test_slice_keeps_name(self): # GH4226 diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 97bae51b18248..54f4e70b36cc2 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -21,7 +21,6 @@ from numpy.random import randn, rand import numpy as np -from numpy.testing import assert_array_equal import pandas as pd from pandas.core.common import (is_sequence, array_equivalent, is_list_like, is_number, @@ -631,34 +630,14 @@ def assert_categorical_equal(res, exp): raise AssertionError("ordered not the same") -def assert_numpy_array_equal(np_array, assert_equal, err_msg=None): - """Checks that 'np_array' is equal to 'assert_equal' +def assert_numpy_array_equal(np_array, assert_equal, + strict_nan=False, err_msg=None): + """Checks that 'np_array' is equivalent to 'assert_equal'. - Note that the expected array should not contain `np.nan`! - Two numpy arrays are equal if all - elements are equal, which is not possible if `np.nan` is such an element! - - If the expected array includes `np.nan` use - `assert_numpy_array_equivalent(...)`. - """ - if np.array_equal(np_array, assert_equal): - return - if err_msg is None: - err_msg = '{0} is not equal to {1}.'.format(np_array, assert_equal) - raise AssertionError(err_msg) - - -def assert_numpy_array_equivalent(np_array, assert_equal, strict_nan=False, err_msg=None): - """Checks that 'np_array' is equivalent to 'assert_equal' - - Two numpy arrays are equivalent if the arrays have equal non-NaN elements, - and `np.nan` in corresponding locations. - - If the the expected array does not contain `np.nan` - `assert_numpy_array_equivalent` is the similar to - `assert_numpy_array_equal()`. If the expected array includes - `np.nan` use this - function. + This is similar to ``numpy.testing.assert_array_equal``, but can + check equality including ``np.nan``. Two numpy arrays are regarded as + equivalent if the arrays have equal non-NaN elements, + and `np.nan` in corresponding locations. """ if array_equivalent(np_array, assert_equal, strict_nan=strict_nan): return @@ -694,7 +673,7 @@ def assert_series_equal(left, right, check_dtype=True, '[datetimelike_compat=True] {0} is not equal to {1}.'.format(left.values, right.values)) else: - assert_numpy_array_equivalent(left.values, right.values) + assert_numpy_array_equal(left.values, right.values) else: assert_almost_equal(left.values, right.values, check_less_precise) if check_less_precise: