home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 591643901

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
591643901 MDExOlB1bGxSZXF1ZXN0Mzk2Nzc0MTAw 3924 Coordinates passed to interp have nan values 30388627 closed 0     9 2020-04-01T05:46:54Z 2020-08-27T08:51:32Z 2020-08-27T08:51:32Z NONE   0 pydata/xarray/pulls/3924

Problem

Keyerror when the coordinates passed to interp have nan value.

Example

``` import numpy as np import xarray as xr

da = xr.DataArray(np.sin(0.3 * np.arange(20).reshape(5, 4)), [('x', np.arange(5)), ('y', [0.1, 0.2, 0.3, 0.4])])

x = xr.DataArray([[0.5, np.nan], [1.5, 2.5]], dims=['z1', 'z2']) y = xr.DataArray([[0.15, 0.2], [np.nan, 0.35]], dims=['z1', 'z2']) da_nan = da.interp(x=x, y=y) ```

Output

E:\miniconda3\envs\satpy\lib\site-packages\pandas\core\indexes\base.py:2826: RuntimeWarning: invalid value encountered in less op(left_distances, right_distances) | (right_indexer == -1), Traceback (most recent call last): File "C:\Users\Xin\Desktop\test_none.py", line 10, in <module> da_nan = da.interp(x=x, y=y) File "E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\dataarray.py", line 1365, in interp **coords_kwargs, File "E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\dataset.py", line 2610, in interp variables[name] = missing.interp(var, var_indexers, method, **kwargs) File "E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\missing.py", line 611, in interp var, indexes_coords = _localize(var, indexes_coords) File "E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\missing.py", line 552, in _localize imin = index.get_loc(np.min(new_x.values), method="nearest") File "E:\miniconda3\envs\satpy\lib\site-packages\pandas\core\indexes\base.py", line 2654, in get_loc raise KeyError(key) KeyError: nan

Solution

Use np.nanmin and np.nanmax in index.get_loc()

Test

Code

``` import numpy as np import xarray as xr

da = xr.DataArray(np.sin(0.3 * np.arange(20).reshape(5, 4)), [('x', np.arange(5)), ('y', [0.1, 0.2, 0.3, 0.4])])

x = xr.DataArray([[0.5, np.nan], [1.5, 2.5]], dims=['z1', 'z2']) y = xr.DataArray([[0.15, 0.2], [np.nan, 0.35]], dims=['z1', 'z2']) da_nan = da.interp(x=x, y=y)

x = xr.DataArray([[0.5, 1], [1.5, 2.5]], dims=['z1', 'z2']) y = xr.DataArray([[0.15, 0.2], [0.25, 0.35]], dims=['z1', 'z2']) da_nonan = da.interp(x=x, y=y)

print('da_nan \n', da_nan) print('da_nonan \n', da_nonan) ```

Output

E:\miniconda3\envs\satpy\lib\site-packages\scipy\interpolate\interpolate.py:2539: RuntimeWarning: invalid value encountered in less out_of_bounds += x < grid[0] E:\miniconda3\envs\satpy\lib\site-packages\scipy\interpolate\interpolate.py:2540: RuntimeWarning: invalid value encountered in greater out_of_bounds += x > grid[-1] da_nan <xarray.DataArray (z1: 2, z2: 2)> array([[ 0.55626357, nan], [ nan, -0.46643289]]) Coordinates: x (z1, z2) float64 0.5 nan 1.5 2.5 y (z1, z2) float64 0.15 0.2 nan 0.35 Dimensions without coordinates: z1, z2 da_nonan <xarray.DataArray (z1: 2, z2: 2)> array([[ 0.55626357, 0.99749499], [ 0.63496063, -0.46643289]]) Coordinates: x (z1, z2) float64 0.5 1.0 1.5 2.5 y (z1, z2) float64 0.15 0.2 0.25 0.35 Dimensions without coordinates: z1, z2

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3924/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 pull

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 9 rows from issue in issue_comments
Powered by Datasette · Queries took 0.596ms · About: xarray-datasette