Skip to content

Add a test for agg std #52371

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
Apr 4, 2023
Merged

Conversation

steliospetrakis02
Copy link
Contributor

I believe that this test ensures the expected output. Let me know if you have any questions or concerns.

@@ -1577,3 +1577,9 @@ def test_agg_groupings_selection():
)
expected = DataFrame({"b": [6, 4], "c": [11, 7]}, index=index)
tm.assert_frame_equal(result, expected)

def test_agg_std():
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
Copy link
Member

@mroeschke mroeschke Apr 3, 2023

Choose a reason for hiding this comment

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

Can you use the exact DataFrame from the issue?


def test_agg_std():
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
std = df.agg(np.std)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std = df.agg(np.std)
expected = df.agg(np.std)

Could you also compare df.agg([np.std])?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @mroeschke, I'm sorry but I'm not sure what you are asking. Do you want me to check the type of class? e.g (pandas.core.series.Series)

Copy link
Member

Choose a reason for hiding this comment

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

Just asking to add a test to also check the result of df.agg([np.std]) as well

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
std = df.agg(np.std)
expected = pd.Series({'A': 1.0, 'B': 1.0}, dtype=float)
assert std.equals(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert std.equals(expected)
tm.assert_series_equal(result, expected)

@mroeschke
Copy link
Member

Can you move the test to pandas/tests/apply/test_frame_apply.py?

@mroeschke mroeschke added Testing pandas testing functions or related to the test suite Apply Apply, Aggregate, Transform, Map labels Apr 3, 2023
@steliospetrakis02
Copy link
Contributor Author

I believe that this will fulfill your request, but please let me know if there is anything else I can do. @mroeschke

tm.assert_series_equal(result, expected)

result = df.agg([np.std])
assert isinstance(result, pd.DataFrame)
Copy link
Member

Choose a reason for hiding this comment

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

Please construct the expected result and use tm.assert_frame_equal

@mroeschke
Copy link
Member

Looks like a few of the code check builds are failing

@steliospetrakis02
Copy link
Contributor Author

@mroeschke , I have fixed the code checks that were failing, and I have constructed the tests as your instructions.

@mroeschke mroeschke added this to the 2.1 milestone Apr 4, 2023
@mroeschke mroeschke merged commit 6d36c45 into pandas-dev:main Apr 4, 2023
@mroeschke
Copy link
Member

Awesome! Thanks @steliospetrakis02

@steliospetrakis02
Copy link
Contributor Author

Awesome! Thanks @steliospetrakis02

You're welcome! I thank you for your guidance and assistance as I take my first steps into contributing to pandas

topper-123 pushed a commit to topper-123/pandas that referenced this pull request Apr 6, 2023
* Add a test for agg std

* move the test as requested and added one more test for df.agg([np.std])

* fix second test

* fix format

* Update test_aggregate.py

* Update test_frame_apply.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Testing pandas testing functions or related to the test suite
Projects
None yet
2 participants