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

Fixes for shapely and scipy updates #174

Merged
merged 26 commits into from
Oct 11, 2024

Conversation

mdpiper
Copy link
Member

@mdpiper mdpiper commented Oct 10, 2024

This PR includes two fixes to pymt for updates to shapely and scipy.

In shapely, the asShape adapters have been removed. The migration guide recommends replacing these adapters (such as asPoint) with geometries (Point). This fixes #164.

In scipy, a bug was identified with the next and previous methods when extrapolating above and below a range, respectively. The expected behavior is for these methods to fail in these situations. This fixes #162.

With these fixes, the version limit on these packages has been removed. I also reverted the "Don't install components for testing" change which was failing because of #164.

@mdpiper
Copy link
Member Author

mdpiper commented Oct 10, 2024

I required numpy<2 for older components. This can be lifted after the components are updated.

On top of this, I added np.set_printoptions(legacy="1.21") to override the default (1.25) that was coming from Landlab, and which isn't allowed in the currently installed numpy, 1.26.4.

@mdpiper
Copy link
Member Author

mdpiper commented Oct 10, 2024

The seven failing tests on Windows are emitted from Landlab from the same Cython file. Here's the last few lines of one of the stack traces:

  ...
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\utils\jaggedarray.py", line 115, in unravel
    unravel(data, offset, out)
  File "src\\landlab\\utils\\ext\\jaggedarray.pyx", line 28, in landlab.utils.ext.jaggedarray.unravel
ValueError: Buffer dtype mismatch, expected 'int64_t' but got 'long'

and here's the full stack trace:

_____________________ test_structured_quadrilateral_grid ______________________
Traceback (most recent call last):
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\runner.py", line 341, in from_call
    result: TResult | None = func()
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\runner.py", line 242, in <lambda>
    lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 182, in _multicall
    return outcome.get_result()
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_result.py", line 100, in get_result
    raise exc.with_traceback(exc.__traceback__)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    teardown.throw(outcome._exception)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\threadexception.py", line 92, in pytest_runtest_call
    yield from thread_exception_runtest_hook()
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\threadexception.py", line 68, in thread_exception_runtest_hook
    yield
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    teardown.throw(outcome._exception)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\unraisableexception.py", line 95, in pytest_runtest_call
    yield from unraisable_exception_runtest_hook()
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\unraisableexception.py", line 70, in unraisable_exception_runtest_hook
    yield
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    teardown.throw(outcome._exception)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\logging.py", line 846, in pytest_runtest_call
    yield from self._runtest_for(item, "call")
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\logging.py", line 829, in _runtest_for
    yield
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    teardown.throw(outcome._exception)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\capture.py", line 880, in pytest_runtest_call
    return (yield)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 167, in _multicall
    teardown.throw(outcome._exception)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\skipping.py", line 257, in pytest_runtest_call
    return (yield)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\runner.py", line 174, in pytest_runtest_call
    item.runtest()
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\python.py", line 1627, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\_pytest\python.py", line 159, in pytest_pyfunc_call
    result = testfunction(**testargs)
  File "D:\a\pymt\pymt\tests\framework\test_bmi_ugrid.py", line 136, in test_structured_quadrilateral_grid
    grid = StructuredQuadrilateral(bmi, grid_id)
  File "D:\a\pymt\pymt\pymt\framework\bmi_ugrid.py", line 206, in __init__
    graph = StructuredQuadGraph(nodes, shape=tuple(shape))
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\graph\structured_quad\structured_quad.py", line 633, in __init__
    StructuredQuadGraphExtras.__init__(self, (node_y, node_x), sort=sort)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\graph\structured_quad\structured_quad.py", line 508, in __init__
    Graph.__init__(
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\graph\graph.py", line 857, in __init__
    self._ds = ugrid_from_unstructured(node_y_and_x, links=links, patches=patches)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\graph\ugrid.py", line 28, in ugrid_from_unstructured
    _update_links_at_patch(ugrid, patches)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\graph\ugrid.py", line 74, in _update_links_at_patch
    patch_links = links_at_patch(patches)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\graph\matrix\at_patch.py", line 40, in links_at_patch
    return unravel(links_at_patch, offset_to_patch, pad=-1)
  File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\utils\jaggedarray.py", line 115, in unravel
    unravel(data, offset, out)
  File "src\\landlab\\utils\\ext\\jaggedarray.pyx", line 28, in landlab.utils.ext.jaggedarray.unravel
ValueError: Buffer dtype mismatch, expected 'int64_t' but got 'long'

@mcflugen
Copy link
Member

...
File "C:\Users\runneradmin\miniconda3\envs\test\lib\site-packages\landlab\utils\jaggedarray.py", line 115, in unravel
unravel(data, offset, out)
File "src\landlab\utils\ext\jaggedarray.pyx", line 28, in landlab.utils.ext.jaggedarray.unravel
ValueError: Buffer dtype mismatch, expected 'int64_t' but got 'long'

That's interesting, I would have thought the Landlab unit tests would have picked this up. I think it should be an easy fix.

@mdpiper
Copy link
Member Author

mdpiper commented Oct 10, 2024

Added Python 3.11 to the tests. We can't go to 3.12 because some older components aren't there yet.

@mdpiper
Copy link
Member Author

mdpiper commented Oct 10, 2024

This is off-topic from the rest of the PR, but because Mambaforge is going away quickly, I did a quick health check on the CI workflows.

@mdpiper mdpiper marked this pull request as ready for review October 10, 2024 20:28
@mdpiper mdpiper requested a review from mcflugen October 10, 2024 20:28
@mdpiper
Copy link
Member Author

mdpiper commented Oct 10, 2024

@mcflugen What do you think we should do? It seems like everything is OK except for the Windows tests which are failing because of an upstream issue.

@mcflugen
Copy link
Member

@mcflugen What do you think we should do? It seems like everything is OK except for the Windows tests which are failing because of an upstream issue.

I think we need a new release of Landlab. I'll have a look but it should be straightforward.

@mcflugen
Copy link
Member

The fix looks like it will be straightforward but I'm not sure how to reproduce the problem so that we know we've fixed it. It looks like the current set of (Landlab) tests already test this case.

@mcflugen
Copy link
Member

@mdpiper I hope that landlab/landlab#2015 fixes this issue. The error you were seeing was caused by the unravel cython function being passed an int32 array were it was expected an int64 array (on Windows long is, sometimes anyway, 32 bit). I've fixed that issue with unravel but I'm not certain why it was getting the int32 array in the first place.

Maybe Windows runners on GA are 32 bit?

@mdpiper
Copy link
Member Author

mdpiper commented Oct 11, 2024

🎉

Copy link
Member

@mcflugen mcflugen left a comment

Choose a reason for hiding this comment

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

👍

@mdpiper mdpiper merged commit df648b4 into master Oct 11, 2024
14 checks passed
@mdpiper mdpiper deleted the mdpiper/fixes-for-shapely-and-scipy-updates branch October 11, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants