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

NumPy 2.1 compatibility for xarray interpolation #2143

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

yaugenst-flex
Copy link
Collaborator

@yaugenst-flex yaugenst-flex commented Jan 7, 2025

Fix TypeError in Box.derivative_face when using NumPy 2.1+ by explicitly converting coord_normal_face from numpy.float64 to Python float before passing to xarray's interpolation. This addresses stricter type checking in NumPy 2.1 while maintaining the same numerical behavior.

Previously this would error like:

...
  File "/Users/yannick/flexcompute/worktrees/surfacemesh_interp/tidy3d/components/geometry/base.py", line 2466, in integrate_face
    arr_at_face = arr.interp(**{dim_normal: coord_normal_face}, assume_sorted=True)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yannick/flexcompute/worktrees/surfacemesh_interp/tidy3d/components/data/data_array.py", line 343, in interp
    return super().interp(coords, method, assume_sorted, kwargs, **coords_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yannick/flexcompute/worktrees/surfacemesh_interp/.venv/lib/python3.12/site-packages/xarray/core/dataarray.py", line 2341, in interp
    ds = self._to_temp_dataset().interp(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yannick/flexcompute/worktrees/surfacemesh_interp/.venv/lib/python3.12/site-packages/xarray/core/dataset.py", line 4004, in interp
    indexers = dict(self._validate_interp_indexers(coords))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yannick/flexcompute/worktrees/surfacemesh_interp/.venv/lib/python3.12/site-packages/xarray/core/dataset.py", line 2859, in _validate_interp_indexers
    raise TypeError(type(v))
TypeError: <class 'numpy.float64'>

Copy link

Copy link

@fyc2646 fyc2646 left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@tomflexcompute tomflexcompute left a comment

Choose a reason for hiding this comment

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

Sorry for using the wrong github login 😅

@yaugenst-flex yaugenst-flex merged commit 1a2e77d into pre/2.8 Jan 8, 2025
15 checks passed
@yaugenst-flex yaugenst-flex deleted the yaugenst-flex/surfacemesh-interp-fix branch January 8, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants