Skip to content

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

Closed
manoj-km24 wants to merge 7 commits into
python:mainfrom
manoj-km24:add-tests-cmath-py
Closed

gh-149924 :Increase test coverage for isclose() function with complex numbers#149923
manoj-km24 wants to merge 7 commits into
python:mainfrom
manoj-km24:add-tests-cmath-py

Conversation

@manoj-km24
Copy link
Copy Markdown
Contributor

@manoj-km24 manoj-km24 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
@manoj-km24 manoj-km24 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))

@manoj-km24 manoj-km24 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

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

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

@manoj-km24
Copy link
Copy Markdown
Contributor Author

The new PR : #149948

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.

6 participants