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

Stats worker may return a complex when pygeoprocessing is built with Cython >= 3.0.0 #342

Closed
phargogh opened this issue Sep 1, 2023 · 0 comments · Fixed by #343
Closed
Assignees
Labels
bug Something isn't working in progress Working on it!

Comments

@phargogh
Copy link
Member

phargogh commented Sep 1, 2023

I came across this exception after rebuilding my container for NCI (forgive the line numbers):

8163 Traceback (most recent call last):
8164   File "/opt/conda/lib/python3.9/multiprocessing/pool.py", line 125, in worker
8165     result = (True, func(*args, **kwds))
8166   File "/home/users/jadoug06/workspace/2021-nci-ndr-sherlock/prep-ndr-inputs-pipeline.py", line 245, in intensified_rainfed_n_app
8167     pygeoprocessing.raster_calculator(
8168   File "/opt/conda/lib/python3.9/site-packages/pygeoprocessing/geoprocessing.py", line 569, in raster_calculator
8169     float(target_stddev))
8170 TypeError: can't convert complex to float

It turns out that in Cython 3.0.0, they included the following change:

The ** power operator now behaves more like in Python by returning the correct complex result if required by math. A new cpow directive was added to turn on the previous C-like behaviour. (Github issue #4936)

When the raster_calculator stats worker does its final computation for the standard deviation, it does the following, taking the square root by way of raising to the 0.5 power:

    if n > 0:
        stats_work_queue.put(
            (min_value, max_value, M_local,
                (S_local / <double>n) ** 0.5))
@phargogh phargogh added bug Something isn't working in progress Working on it! labels Sep 1, 2023
@phargogh phargogh self-assigned this Sep 1, 2023
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress Working on it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant