Skip to content

gh-149924 :Increase test coverage for isclose() function with complex numbers#149923

Closed
ghost wants to merge 7 commits into
mainfrom
unknown repository
Closed

gh-149924 :Increase test coverage for isclose() function with complex numbers#149923
ghost wants to merge 7 commits into
mainfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented May 16, 2026

In Lib/test/test_cmath.py, the isclose() function misses certain special test cases for special complex numbers with infinity and Nan. As docs tell:

-inf, inf and NaN behave similarly to the IEEE 754 Standard. 
That is, NaN is not close to anything, even itself. 
inf and -inf are only close to themselves. 

This applies for complex numbers as well (inf + infj , -inf - infj and NaN + NaNj behave in the same way).
This PR adds additional tests for these edge cases.

@bedevere-app bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels May 16, 2026
@ghost ghost changed the title Increase test coverage for isclose() function with complex numbers gh-149924 :Increase test coverage for isclose() function with complex numbers May 16, 2026
@aisk aisk added the skip news label May 16, 2026
Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Please add more cases: for example self.assertIsNotClose(complex(INF, INF), complex(-INF, -INF)) is not covered

Comment thread Lib/test/test_cmath.py Outdated
Comment on lines +587 to +589
self.assertIsClose(complex(INF,INF),complex(INF,INF))
self.assertIsClose(complex(-INF,-INF),complex(-INF,-INF))
self.assertIsNotClose(complex(NAN,NAN),complex(NAN,NAN))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
self.assertIsClose(complex(INF,INF),complex(INF,INF))
self.assertIsClose(complex(-INF,-INF),complex(-INF,-INF))
self.assertIsNotClose(complex(NAN,NAN),complex(NAN,NAN))
self.assertIsClose(complex(INF, INF), complex(INF, INF))
self.assertIsClose(complex(-INF, -INF), complex(-INF, -INF))
self.assertIsNotClose(complex(NAN, NAN), complex(NAN, NAN))

@ghost ghost requested review from a team, ericsnowcurrently and gpshead as code owners May 17, 2026 11:03
@python-cla-bot
Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@ghost ghost closed this May 17, 2026
@ghost ghost deleted the add-tests-cmath-py branch May 17, 2026 11:08
@ghost
Copy link
Copy Markdown
Author

ghost commented May 17, 2026

@sobolevn Sorry, I mistakenly polluted this PR. I will open a new one shortly.

@ghost
Copy link
Copy Markdown
Author

ghost commented May 17, 2026

The new PR : #149948

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants