Skip to content

Remove return values for asserts #25462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/io/parser/test_textreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,4 @@ 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),
np.asarray(right[k]))
tm.assert_numpy_array_equal(np.asarray(v), np.asarray(right[k]))
2 changes: 1 addition & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename this routine to tm.assert_is_sorted


data = {'a': 0, 'b': '1', 'c': '2', 'd': datetime.now()}
series = Series(data)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tools/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 23 additions & 22 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -322,7 +322,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,
Expand Down Expand Up @@ -360,7 +360,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):
Expand Down Expand Up @@ -967,10 +967,11 @@ def isiterable(obj):


def is_sorted(seq):
"""Assert that the sequence is 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,
Expand Down Expand Up @@ -1168,8 +1169,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,
Expand Down Expand Up @@ -1324,11 +1323,13 @@ 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)
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)):
return assert_extension_array_equal(left.array, right.array)
assert_extension_array_equal(left.array, right.array)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same don't need a return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this earlier but some of the tests failed so I added the returns back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 091a00e (this was in response to an earlier PR comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this just returns None which is the same as if you leave the return out, pls remove


else:
_testing.assert_almost_equal(left.get_values(), right.get_values(),
Expand Down