pytroll / pyresample

Geospatial image resampling in Python
http://pyresample.readthedocs.org
GNU Lesser General Public License v3.0
346 stars 94 forks source link

Fix geocentric_resolution compatibility with numpy 2.1.0 #614

Closed djhoese closed 3 weeks ago

djhoese commented 3 weeks ago

Satpy unstable environment started failing and regular environments will start failing too when conda-forge has numpy 2.1.0 available.

Starting with numpy 2.1.0 the numpy function histogram_bin_edges will raise a ValueError if the array you give it can't be split into the number of buckets you request (default 10). This happens when the elements of an array are so close together (near floating point precision) that numpy can't possibly split things into N buckets. There error you get is:

E               ValueError: Too many bins for data range. Cannot create 10 finite-sized bins.

This PR works around this by adding a try/except to the call and just returning the two elements of the input array. As far as I can tell this is basically equivalent.

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 93.97%. Comparing base (5f69bd8) to head (0a47fd3). Report is 5 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #614 +/- ## ======================================= Coverage 93.97% 93.97% ======================================= Files 86 86 Lines 13811 13819 +8 ======================================= + Hits 12979 12987 +8 Misses 832 832 ``` | [Flag](https://app.codecov.io/gh/pytroll/pyresample/pull/614/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/pytroll/pyresample/pull/614/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `93.97% <100.00%> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

djhoese commented 3 weeks ago

Hm pre-commit on my local machine is behaving differently than pre-commit.ci.