Skip to content
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

Fix bugs in the Python implementation of inner1d and length #265

Merged
merged 5 commits into from
May 15, 2024

Conversation

mcara
Copy link
Member

@mcara mcara commented Apr 30, 2024

This PR should fix (for now some) errors in unit tests when C math_util is not available.

length() needs more investigation (but the biggest difference in how nan are treated in comparisons: C code considers two nan equal) and I will do that in about 1 week from now.

Fix #261

CC: @jhunkeler @pllim

@mcara mcara requested a review from a team as a code owner April 30, 2024 08:18
@mcara mcara added the bug label Apr 30, 2024
Copy link

codecov bot commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 30.43478% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 80.33%. Comparing base (5de7fc7) to head (dd32324).
Report is 4 commits behind head on master.

Files Patch % Lines
spherical_geometry/great_circle_arc.py 28.57% 15 Missing ⚠️
spherical_geometry/polygon.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #265      +/-   ##
==========================================
- Coverage   81.28%   80.33%   -0.96%     
==========================================
  Files           5        5              
  Lines        1010     1017       +7     
==========================================
- Hits          821      817       -4     
- Misses        189      200      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pllim pllim added the Build wheels Build wheels on PR label Apr 30, 2024
@@ -28,7 +28,7 @@


def _inner1d_np(x, y):
return np.multiply(x, y).sum(axis=1)
return np.multiply(x, y).sum(axis=-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

So subtle. Does this need a regression test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea! I'll do it in a week

@pllim
Copy link
Contributor

pllim commented Apr 30, 2024

This does fix the devdeps job, so if you don't want to add a test, feel free to merge. Thanks!

@mcara
Copy link
Member Author

mcara commented Apr 30, 2024

I think this should fix failing tests and the Python versions of length and inner1d. I disabled one test: I don't think it is critical and I will think about it in a week.

Unit tests for would be a plus but no time now.

@@ -529,7 +529,7 @@ def test_math_util_angle_domain():
)


@pytest.mark.skipif(math_util is None, reason="math_util C-ext is missing")
@pytest.mark.skip(reason="temporary turning this off")
Copy link
Contributor

Choose a reason for hiding this comment

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

But isn't think just another variation of this that was not accepted?

@jhunkeler jhunkeler mentioned this pull request May 2, 2024
@mcara mcara force-pushed the fix-inner1d-and-length branch 5 times, most recently from 76aee62 to dd631e1 Compare May 12, 2024 19:37
@mcara
Copy link
Member Author

mcara commented May 12, 2024

Tests with numpy>2.0.0 are passing after #270 and

# "numpy>=2.0.0dev0",
uncommented.

Screenshot 2024-05-12 at 3 44 04 PM

@mcara mcara requested a review from jhunkeler May 12, 2024 22:39
@mcara mcara self-assigned this May 12, 2024
@mcara
Copy link
Member Author

mcara commented May 12, 2024

After commit c99e74e most tests (except for one that we skip) with numpy implementation of quad-accuracy functions from math_util pass.

I will now remove tricks used for testing purpose and squash most commits.

@@ -54,7 +54,7 @@ requires = [
"setuptools>=61.2",
"setuptools_scm[toml]>=3.6",
"numpy>=1.25",
# "numpy>=2.0.0dev0",
#"numpy>=2.0.0dev0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be deleted altogether?

Suggested change
#"numpy>=2.0.0dev0",

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, I left it there for easy switching to numpy 2.0 - that's the reason. Are you asking @jhunkeler ? I hope he has a better solution.

Copy link
Contributor

@pllim pllim May 13, 2024

Choose a reason for hiding this comment

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

Oh... this is build requirements. In that case, I think you can just use numpy 2.x like astropy though you might want to pick up RC2 instead of RC1 by now.

https://github.com/astropy/astropy/blob/566fcbd4a36b787564a46b01c4c8322448076d99/pyproject.toml#L133

They claim the 2.x ABI is backward compatible for numpy>=1.23.

xref numpy/numpy#24300 and astropy/astropy#16257

Copy link
Member Author

Choose a reason for hiding this comment

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

but if I mention @jhunkeler a couple of times more, we might get an even better solution

Copy link
Contributor

Choose a reason for hiding this comment

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

🧟‍♂️
If the code we have now is backward compatible and our pin is numpy>=1.25, then I suspect it won't be a big deal whenever 2.0 is released. The pins as they are right now (here^) will let tox do what it needs to do. We'll be able to test numpy 1.x and 2.x without any trouble from the build system.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

In that case, let's do it.

@@ -54,7 +54,7 @@ requires = [
"setuptools>=61.2",
"setuptools_scm[toml]>=3.6",
"numpy>=1.25",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"numpy>=1.25",
"numpy>=2.0.0rc2",

@mcara mcara merged commit 898f364 into spacetelescope:master May 15, 2024
22 of 24 checks passed
@jhunkeler jhunkeler mentioned this pull request May 15, 2024
@mcara mcara mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Build wheels Build wheels on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: 27 test failures with numpy 2.1.dev
3 participants