Skip to content

TST: GH26650, added new test to validate numpy matmul function with dataframes #47427

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 6 commits into from
Jun 21, 2022
Merged
Changes from 2 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
10 changes: 10 additions & 0 deletions pandas/tests/series/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,13 @@ def test_outer():

with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
np.subtract.outer(s, o)


def test_npmul():
# https://github.com/pandas-dev/pandas/issues/26650
data = np.random.randint(0, 10, 100, dtype="int64")
df = pd.DataFrame({"nums": data})
dfT = df.T
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid these functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing and the feedback. I removed these lines and declared everything directly on the assert statement. Just for my understanding, these lines needed to be removed since they introduce too many variables?

Copy link
Member

Choose a reason for hiding this comment

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

No, we try to define tests in a way that they do not rely on functions that are not tested itself. E.g. .T was not necessary to reproduce the behavior.

You can do it like:

df=...
result=...
expected=...
arm.assert_frame_equal(result, expected)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ok, I see. Thanks again! I modified the PR to reflect this.


expected_result = pd.DataFrame(index=["nums"], data=[np.sum(np.square(data))])
assert expected_result.equals(np.matmul(dfT, df))