home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 1460877702

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/7597#issuecomment-1460877702 https://api.github.com/repos/pydata/xarray/issues/7597 1460877702 IC_kwDOAMm_X85XEzmG 127195910 2023-03-08T21:08:17Z 2023-03-14T19:40:34Z NONE

The interpolate_na method in xarray can be used to interpolate missing values in a dataset or data array. The max_gap argument is used to specify the maximum number of consecutive NaN values that can be interpolated. The max_map argument is used to specify the maximum number of interpolated values that can be used for each NaN value.

It's worth noting that the max_map argument only limits the number of interpolated values that can be used for each NaN value, but it does not limit the total number of interpolated values that can be used in the dataset. This means that if there are multiple consecutive NaN values, the max_map argument may not work as expected at the boundaries of the array.

Here's an example to illustrate this issue:

import xarray as xr import numpy as np

create a sample data array with a missing value at the beginning and end

data = np.array([np.nan, 1, 2, 3, 4, np.nan])

create a dataset with the sample data array

ds = xr.Dataset({'foo': (['x'], data)}, coords={'x': np.arange(6)})

interpolate missing values with a max_map of 2

ds_interp = ds.interpolate_na(max_gap=1, max_map=2)

In this example, we have a data array with missing values at the beginning and end, and we interpolate the missing values using a max_map of 2. However, the resulting dataset still has 4 interpolated values, which is more than the max_map of 2. This is because the max_map argument is only limiting the number of interpolated values that can be used for each NaN value, but it is not limiting the total number of interpolated values that can be used in the dataset.

To limit the total number of interpolated values in the dataset, you can use the limit argument, which specifies the maximum number of interpolated values that can be used in the entire dataset. Here's an example:

interpolate missing values with a max_map of 2 and a limit of 2

ds_interp = ds.interpolate_na(max_gap=1, max_map=2, limit=2)

In this example, we add a limit argument of 2, which limits the total number of interpolated values in the dataset to 2. This results in only 2 interpolated values in the resulting dataset, which is consistent with the limit argument.

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  1615599224
Powered by Datasette · Queries took 0.7ms · About: xarray-datasette