Skip to content

TST: Remove even more uses np.array_equal in tests #18087

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 1 commit into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_modulo(self):
s = p[0]
res = s % p
res2 = p % s
assert not np.array_equal(res.fillna(0), res2.fillna(0))
Copy link
Contributor

Choose a reason for hiding this comment

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

so another way to do this and maybe cleaner is to have a parameter compare='equal|'not_equal'
The main issue I have with this method is the error messages are not as good (though maybe it doesn't matter)

Copy link
Member Author

@gfyoung gfyoung Nov 3, 2017

Choose a reason for hiding this comment

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

IIUC, wouldn't I have to propagate that parameter across every single assert_* function? My change allow for any assert_* function to be passed in.

Also, I'm not sure I follow what error message you would expect. If the assert_* function passes when it isn't supposed to, you can't specify what was "different" in this case.

Copy link
Member Author

@gfyoung gfyoung Nov 4, 2017

Choose a reason for hiding this comment

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

@jreback : As I explained why I wasn't really a fan passing in a compare parameter to all of these assert_* functions, if you have any other thoughts on this point, let me know. Otherwise, I think this should be good to go.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jreback : Any thoughts?

assert not res.fillna(0).equals(res2.fillna(0))

def test_div(self):

Expand Down Expand Up @@ -271,7 +271,7 @@ def test_div(self):
s = p[0]
res = s / p
res2 = p / s
assert not np.array_equal(res.fillna(0), res2.fillna(0))
assert not res.fillna(0).equals(res2.fillna(0))

def test_logical_operators(self):

Expand Down Expand Up @@ -1030,7 +1030,7 @@ def test_boolean_comparison(self):
assert_numpy_array_equal(result, expected.values)

pytest.raises(ValueError, lambda: df == b_c)
assert not np.array_equal(df.values, b_c)
assert df.values.shape != b_c.shape

# with alignment
df = DataFrame(np.arange(6).reshape((3, 2)),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def test_modulo(self):
p = p.astype('float64')
result = p['first'] % p['second']
result2 = p['second'] % p['first']
assert not np.array_equal(result, result2)
assert not result.equals(result2)

# GH 9144
s = Series([0, 1])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_div(self):
assert_series_equal(result, p['first'].astype('float64'),
check_names=False)
assert result.name is None
assert not np.array_equal(result, p['second'] / p['first'])
assert not result.equals(p['second'] / p['first'])

# inf signing
s = Series([np.nan, 1., -1.])
Expand Down