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

Fill gaps limited 7665 #9402

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbfc476
Introduce new arguments limit_direction, limit_area, limit_use coordi…
Ockenfuss Jun 10, 2024
16cdf30
Use internal broadcasting and transpose instead of ones_like
Ockenfuss Jun 10, 2024
43b7165
Typo: Default False in doc for limit_use_coordinates
Ockenfuss Jun 10, 2024
d46baa4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2024
1fb7795
Towards masked implementation
Ockenfuss Jun 11, 2024
878e6bb
Working fill_gaps implementation
Ockenfuss Jun 20, 2024
1ac5e9c
Remove keep_attrs from docstring of filling functions
Ockenfuss Aug 23, 2024
97b00a4
Fix typos, undo empty spaces, remove temporarily introduced arguments
Ockenfuss Aug 23, 2024
1626489
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2024
b3d70d6
Add line break for readability
Ockenfuss Aug 24, 2024
6b4c0f7
Enforce kwargs to be passed by name
Ockenfuss Aug 24, 2024
84fe728
Keep_Attrs: Default to True
Ockenfuss Aug 24, 2024
3bbd6da
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 24, 2024
3ec34bf
Explicitly add fill functions in GapMask object
Ockenfuss Aug 25, 2024
a64809a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 25, 2024
92c6b2a
Add type hints to most arguments, return types
Ockenfuss Aug 25, 2024
5452df1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 25, 2024
2f53449
Fix accidental double pasting of arguments
Ockenfuss Aug 25, 2024
3696d63
Fix more mypy errors
Ockenfuss Aug 25, 2024
d5d56ae
Bottleneck is required for limit functionality
Ockenfuss Aug 25, 2024
7570b62
Docs: Require numbagg or bottleneck for ffill/bfill/fill_gaps
Ockenfuss Aug 26, 2024
f19f626
Rework index conversion to have consistent typing
Ockenfuss Aug 26, 2024
b5025ff
Add new method to api.rst
Ockenfuss Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3776,6 +3776,8 @@ def fill_gaps(
"""Fill in gaps in the data using one of several filling methods.
Allows for fine control on how far to extend the valid data into the gaps and the maximum size of the gaps to fill.

*Requires bottleneck.*
Ockenfuss marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
dim : Hashable
Expand Down
2 changes: 2 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6884,6 +6884,8 @@ def fill_gaps(
"""Fill in gaps in the data using one of several filling methods.
Allows for fine control on how far to extend the valid data into the gaps and the maximum size of the gaps to fill.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we clearly list the methods here on the returned object? (Or lmk if I'm missing them — they're in the doctest but otherwise I don't see them, thanks)


*Requires bottleneck.*

Parameters
----------
dim : Hashable
Expand Down
13 changes: 13 additions & 0 deletions xarray/tests/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def test_interpolate_limits():
assert_equal(actual, expected)


@requires_bottleneck
def test_interpolate_double_coordinate():
# Check if max_gap is able to handle string coordinate names
# Limit is always refering to an index
Expand Down Expand Up @@ -633,6 +634,7 @@ def test_bfill_dataset(ds):
ds.ffill(dim="time")


@requires_bottleneck
def test_get_gap_left_edge():
n = np.nan
arr = [
Expand Down Expand Up @@ -664,6 +666,7 @@ def test_get_gap_left_edge():
)


@requires_bottleneck
def test_get_gap_right_edge():
n = np.nan
arr = [
Expand Down Expand Up @@ -695,6 +698,7 @@ def test_get_gap_right_edge():
)


@requires_bottleneck
def test_get_gap_dist_to_left_edge():
n = np.nan
arr = [
Expand All @@ -718,6 +722,7 @@ def test_get_gap_dist_to_left_edge():
expected = da.copy(data=[[n, 0, 3, 4, 5, 6, 8, 10, 0], [n, n, n, 0, 1, 2, 0, 2, 4]])


@requires_bottleneck
def test_get_gap_dist_to_right_edge():
n = np.nan
arr = [
Expand Down Expand Up @@ -768,6 +773,7 @@ def test_get_nan_block_lengths(y, lengths_expected):
assert_equal(actual, expected)


@requires_bottleneck
def test_get_nan_block_lengths_2d():
n = np.nan
da = xr.DataArray(
Expand Down Expand Up @@ -804,6 +810,7 @@ def test_get_nan_block_lengths_2d():
assert_equal(actual, expected_y)


@requires_bottleneck
def test_get_limit_fill_mask():
T = True
F = False
Expand Down Expand Up @@ -856,6 +863,7 @@ def test_get_limit_fill_mask():
assert_equal(actual, expected)


@requires_bottleneck
def test_get_area_mask():
T = True
F = False
Expand Down Expand Up @@ -1064,6 +1072,7 @@ def test_interpolate_na_max_gap_2d(coords):
assert_equal(actual, expected_x)


@requires_bottleneck
def test_interpolate_na_limit_2d():
n = np.nan
times = pd.date_range("2000-01-01", periods=12, freq="3h")
Expand Down Expand Up @@ -1113,6 +1122,7 @@ def test_interpolators_complex_out_of_bounds():


####Masking Functionality
@requires_bottleneck
def test_fill_gaps_limit():
n = np.nan
times = pd.date_range("2000-01-01", periods=8, freq="2h")
Expand Down Expand Up @@ -1149,6 +1159,7 @@ def test_fill_gaps_limit():
assert_equal(actual, expected)


@requires_bottleneck
def test_mask_gap_limit_2d():
n = np.nan
times = pd.date_range("2000-01-01", periods=12, freq="3h")
Expand Down Expand Up @@ -1309,6 +1320,7 @@ def test_mask_gap_limit_2d():
assert_equal(actual, expected)


@requires_bottleneck
def test_mask_gap_max_gap_2d():
n = np.nan
times = pd.date_range("2000-01-01", periods=12, freq="3h")
Expand Down Expand Up @@ -1358,6 +1370,7 @@ def test_mask_gap_max_gap_2d():
assert_equal(actual, expected)


@requires_bottleneck
def test_mask_double_coordinate():
# Check if limit and max_gap are able to handle string coordinate names
n = np.nan
Expand Down
Loading