From 8b2f085529c607f620f0003cf7dfd20eec9d2a4b Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 27 Feb 2019 18:52:32 +0000 Subject: [PATCH 01/13] Remove return values for asserts Unless they are context managers. --- pandas/util/testing.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index f441dd20f3982..c7fdcbba1a5f3 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -321,7 +321,7 @@ def assert_almost_equal(left, right, check_dtype="equiv", else: obj = "Input" assert_class_equal(left, right, obj=obj) - return _testing.assert_almost_equal( + _testing.assert_almost_equal( left, right, check_dtype=check_dtype, check_less_precise=check_less_precise, @@ -359,7 +359,7 @@ def _check_isinstance(left, right, cls): def assert_dict_equal(left, right, compare_keys=True): _check_isinstance(left, right, dict) - return _testing.assert_dict_equal(left, right, compare_keys=compare_keys) + _testing.assert_dict_equal(left, right, compare_keys=compare_keys) def randbool(size=(), p=0.5): @@ -1167,8 +1167,6 @@ def _raise(left, right, err_msg): if isinstance(left, np.ndarray) and isinstance(right, np.ndarray): assert_attr_equal('dtype', left, right, obj=obj) - return True - def assert_extension_array_equal(left, right, check_dtype=True, check_less_precise=False, From aaca9a7334a43b292d194ccbe82e56a8170f4b55 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sun, 3 Mar 2019 14:14:35 +0000 Subject: [PATCH 02/13] Dont assert functions that assert assert either raises or doesn't. If it doesn't tm.assert_* returns None, and there's no need to assert XXX is None. --- pandas/tests/indexes/interval/test_interval.py | 4 ++-- pandas/tests/io/parser/test_textreader.py | 2 +- pandas/tests/tools/test_numeric.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexes/interval/test_interval.py b/pandas/tests/indexes/interval/test_interval.py index e4f25ff143273..711313673abfc 100644 --- a/pandas/tests/indexes/interval/test_interval.py +++ b/pandas/tests/indexes/interval/test_interval.py @@ -541,12 +541,12 @@ def test_get_loc_datetimelike_overlapping(self, arrays): value = index[0].mid + Timedelta('12 hours') result = np.sort(index.get_loc(value)) expected = np.array([0, 1], dtype='intp') - assert tm.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) interval = Interval(index[0].left, index[1].right) result = np.sort(index.get_loc(interval)) expected = np.array([0, 1, 2], dtype='intp') - assert tm.assert_numpy_array_equal(result, expected) + tm.assert_numpy_array_equal(result, expected) # To be removed, replaced by test_interval_new.py (see #16316, #16386) def test_get_indexer(self): diff --git a/pandas/tests/io/parser/test_textreader.py b/pandas/tests/io/parser/test_textreader.py index 8119de67890a5..2d3327256e23e 100644 --- a/pandas/tests/io/parser/test_textreader.py +++ b/pandas/tests/io/parser/test_textreader.py @@ -349,5 +349,5 @@ def test_empty_csv_input(self): def assert_array_dicts_equal(left, right): for k, v in compat.iteritems(left): - assert tm.assert_numpy_array_equal(np.asarray(v), + tm.assert_numpy_array_equal(np.asarray(v), np.asarray(right[k])) diff --git a/pandas/tests/tools/test_numeric.py b/pandas/tests/tools/test_numeric.py index 97e1dc2f6aefc..b7c6b8eca2b15 100644 --- a/pandas/tests/tools/test_numeric.py +++ b/pandas/tests/tools/test_numeric.py @@ -242,7 +242,7 @@ def test_really_large_scalar(large_val, signed, transform, errors): else: expected = float(val) if (errors == "coerce" and val_is_string) else val - assert tm.assert_almost_equal(to_numeric(val, **kwargs), expected) + tm.assert_almost_equal(to_numeric(val, **kwargs), expected) def test_really_large_in_arr(large_val, signed, transform, From 220052a8cf87757f20f3769f5a4993b35c0a6e2c Mon Sep 17 00:00:00 2001 From: Samuel Date: Sun, 3 Mar 2019 14:24:18 +0000 Subject: [PATCH 03/13] flake8 --- pandas/tests/io/parser/test_textreader.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/io/parser/test_textreader.py b/pandas/tests/io/parser/test_textreader.py index 2d3327256e23e..22e0ce775e21f 100644 --- a/pandas/tests/io/parser/test_textreader.py +++ b/pandas/tests/io/parser/test_textreader.py @@ -349,5 +349,4 @@ def test_empty_csv_input(self): def assert_array_dicts_equal(left, right): for k, v in compat.iteritems(left): - tm.assert_numpy_array_equal(np.asarray(v), - np.asarray(right[k])) + tm.assert_numpy_array_equal(np.asarray(v), np.asarray(right[k])) From 394fd96f166864f40fc76e6a547d3ee1e43dc1e7 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sun, 3 Mar 2019 15:03:10 +0000 Subject: [PATCH 04/13] testing.util.is_sorted raises AssertionError --- pandas/tests/series/test_constructors.py | 2 +- pandas/util/testing.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index d92ca48751d0a..fd921b52f4903 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1009,7 +1009,7 @@ def test_fromDict(self): data = {'a': 0, 'b': 1, 'c': 2, 'd': 3} series = Series(data) - assert tm.is_sorted(series.index) + tm.is_sorted(series.index) data = {'a': 0, 'b': '1', 'c': '2', 'd': datetime.now()} series = Series(data) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 7e99530870014..ddb3748374d66 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -967,10 +967,11 @@ def isiterable(obj): def is_sorted(seq): + """raises assertion error if the input sequence isn't sorted.""" if isinstance(seq, (Index, Series)): seq = seq.values # sorting does not change precisions - return assert_numpy_array_equal(seq, np.sort(np.array(seq))) + assert_numpy_array_equal(seq, np.sort(np.array(seq))) def assert_categorical_equal(left, right, check_dtype=True, From 09ebf427294fc4c39f79f5051f69ea53f70dd03e Mon Sep 17 00:00:00 2001 From: Samuel Date: Sun, 3 Mar 2019 19:24:08 +0000 Subject: [PATCH 05/13] Improve is_sorted docstring --- pandas/util/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index ddb3748374d66..bcb4ce1b0bea6 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -967,7 +967,7 @@ def isiterable(obj): def is_sorted(seq): - """raises assertion error if the input sequence isn't sorted.""" + """Assert that the sequence is sorted.""" if isinstance(seq, (Index, Series)): seq = seq.values # sorting does not change precisions From 60ec5ee80b46a8a4828c0aa0da023e2b14d465e2 Mon Sep 17 00:00:00 2001 From: Sam Sinayoko Date: Mon, 4 Mar 2019 07:50:51 +0000 Subject: [PATCH 06/13] remove remaining return assert_* statements --- pandas/util/testing.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index bcb4ce1b0bea6..0e4f0df209dcf 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -286,25 +286,25 @@ def assert_almost_equal(left, right, check_dtype="equiv", """ if isinstance(left, pd.Index): - return assert_index_equal(left, right, - check_exact=False, - exact=check_dtype, - check_less_precise=check_less_precise, - **kwargs) + assert_index_equal(left, right, + check_exact=False, + exact=check_dtype, + check_less_precise=check_less_precise, + **kwargs) elif isinstance(left, pd.Series): - return assert_series_equal(left, right, - check_exact=False, - check_dtype=check_dtype, - check_less_precise=check_less_precise, - **kwargs) + assert_series_equal(left, right, + check_exact=False, + check_dtype=check_dtype, + check_less_precise=check_less_precise, + **kwargs) elif isinstance(left, pd.DataFrame): - return assert_frame_equal(left, right, - check_exact=False, - check_dtype=check_dtype, - check_less_precise=check_less_precise, - **kwargs) + assert_frame_equal(left, right, + check_exact=False, + check_dtype=check_dtype, + check_less_precise=check_less_precise, + **kwargs) else: # Other sequences. From 091a00e2aa5a7bb81a16731ad77ca11405e514d6 Mon Sep 17 00:00:00 2001 From: Sam Sinayoko Date: Mon, 4 Mar 2019 10:46:14 +0000 Subject: [PATCH 07/13] remove remaining "return assert_*" statements in testing.py --- pandas/util/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 0e4f0df209dcf..db89c73460ff4 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1323,11 +1323,11 @@ def assert_series_equal(left, right, check_dtype=True, # .values is an ndarray, but ._values is the ExtensionArray. # TODO: Use .array assert is_extension_array_dtype(right.dtype) - return assert_extension_array_equal(left._values, right._values) + assert_extension_array_equal(left._values, right._values) elif (is_extension_array_dtype(left) and not is_categorical_dtype(left) and is_extension_array_dtype(right) and not is_categorical_dtype(right)): - return assert_extension_array_equal(left.array, right.array) + assert_extension_array_equal(left.array, right.array) else: _testing.assert_almost_equal(left.get_values(), right.get_values(), From e600bbef13e9ec0e595208a59aef9a25a105812a Mon Sep 17 00:00:00 2001 From: Sam Sinayoko Date: Tue, 5 Mar 2019 08:47:31 +0000 Subject: [PATCH 08/13] Fix broken tests --- pandas/util/testing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index db89c73460ff4..a59ccd9780199 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1324,10 +1324,12 @@ def assert_series_equal(left, right, check_dtype=True, # TODO: Use .array assert is_extension_array_dtype(right.dtype) assert_extension_array_equal(left._values, right._values) + return elif (is_extension_array_dtype(left) and not is_categorical_dtype(left) and is_extension_array_dtype(right) and not is_categorical_dtype(right)): assert_extension_array_equal(left.array, right.array) + return else: _testing.assert_almost_equal(left.get_values(), right.get_values(), From ce3a0a1168004e45801cbee325abdb1fd38e1c5d Mon Sep 17 00:00:00 2001 From: Sam Sinayoko Date: Tue, 26 Mar 2019 07:58:00 +0000 Subject: [PATCH 09/13] Rename is_sorted to assert_is_sorted --- pandas/tests/series/test_constructors.py | 2 +- pandas/util/testing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index fd921b52f4903..70fa58a3ce257 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1009,7 +1009,7 @@ def test_fromDict(self): data = {'a': 0, 'b': 1, 'c': 2, 'd': 3} series = Series(data) - tm.is_sorted(series.index) + tm.assert_is_sorted(series.index) data = {'a': 0, 'b': '1', 'c': '2', 'd': datetime.now()} series = Series(data) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index a59ccd9780199..9f491e2aff9a9 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -966,7 +966,7 @@ def isiterable(obj): return hasattr(obj, '__iter__') -def is_sorted(seq): +def assert_is_sorted(seq): """Assert that the sequence is sorted.""" if isinstance(seq, (Index, Series)): seq = seq.values From 24f3b740ad2b8e87dd5897a4afd1f0944ff1167b Mon Sep 17 00:00:00 2001 From: Sam Sinayoko Date: Wed, 10 Apr 2019 08:25:34 +0100 Subject: [PATCH 10/13] reactivate metadata comparison --- pandas/util/testing.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 0f5d705ed938f..4443f65ef71cd 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1106,13 +1106,9 @@ def assert_series_equal(left, right, check_dtype=True, # TODO: Use .array assert is_extension_array_dtype(right.dtype) assert_extension_array_equal(left._values, right._values) - return - elif (is_extension_array_dtype(left) and not is_categorical_dtype(left) and is_extension_array_dtype(right) and not is_categorical_dtype(right)): assert_extension_array_equal(left.array, right.array) - return - else: _testing.assert_almost_equal(left.get_values(), right.get_values(), check_less_precise=check_less_precise, From f678030397b3759b0977138c18ba0098fdfe92b4 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Wed, 1 May 2019 07:48:13 -0400 Subject: [PATCH 11/13] handle expected in integer array testing --- pandas/tests/arrays/test_integer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index b88ba1cf01426..759dacd7f221e 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -159,7 +159,7 @@ def _check_op(self, s, op_name, other, exc=None): # integer result type else: - rs = pd.Series(s.values._data) + rs = pd.Series(s.values._data, name=s.name) expected = op(rs, other) self._check_op_integer(result, expected, mask, s, op_name, other) From b72e99f0a2cd7ecabaed6c8fbe673ae3eb79340a Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Sun, 5 May 2019 18:28:50 -0400 Subject: [PATCH 12/13] fixed assert --- pandas/tests/io/parser/test_textreader.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/parser/test_textreader.py b/pandas/tests/io/parser/test_textreader.py index eb3789bb72910..2177d6bb93108 100644 --- a/pandas/tests/io/parser/test_textreader.py +++ b/pandas/tests/io/parser/test_textreader.py @@ -345,5 +345,5 @@ def test_empty_csv_input(self): def assert_array_dicts_equal(left, right): for k, v in left.items(): - assert tm.assert_numpy_array_equal(np.asarray(v), - np.asarray(right[k])) + tm.assert_numpy_array_equal(np.asarray(v), + np.asarray(right[k])) From f4497fd03a45241b0836cac40bf776561c2b8baf Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Mon, 6 May 2019 20:12:59 -0400 Subject: [PATCH 13/13] fix test --- pandas/tests/reductions/test_reductions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 76ac5353c5916..c91233e9317b7 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -147,7 +147,7 @@ def test_same_tz_min_max_axis_1(self, op, expected_col): columns=['a']) df['b'] = df.a.subtract(pd.Timedelta(seconds=3600)) result = getattr(df, op)(axis=1) - expected = df[expected_col] + expected = df[expected_col].rename(None) tm.assert_series_equal(result, expected)