Skip to content

Conversation

shaurya5
Copy link

@shaurya5 shaurya5 commented Oct 3, 2025


ser2 = Series([1 + 2j, 2 + 3j, 3 + 4j], dtype=np.complex128)
expected_var = 2.0
tm.assert_almost_equal(ser2.var(ddof=1), expected_var)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need assert_almost_equal or can we use assert_series_equal?

Copy link
Author

Choose a reason for hiding this comment

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

We need assert_almost_equal because .var() will return a scalar not a series

Copy link
Member

Choose a reason for hiding this comment

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

Can you instead adjust the expected value to be the right type of output? The point of assert_almost_equal is to allow for differences in precision, but not necessarily in types

ser2.var(ddof=1), np.var([1 + 2j, 2 + 3j, 3 + 4j], ddof=1)
)

# Test with NaN
Copy link
Member

Choose a reason for hiding this comment

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

Rather than creating multiple variables it would be better to parametrize the inputs to this test

Copy link
Author

Choose a reason for hiding this comment

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

added the inputs as parameters

# Test other ddof values
tm.assert_almost_equal(ser2.var(ddof=0), 4 / 3)

# Test that imaginary part is preserved in mean calculation
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it should be a separate test

Copy link
Author

Choose a reason for hiding this comment

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

made this a separate test

@mroeschke mroeschke added the Reduction Operations sum, mean, min, max, etc. label Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Incorrect results for pandas.Series.var
3 participants