From 75b03052af695ff475ed312b9f217896e9307fa4 Mon Sep 17 00:00:00 2001 From: Constantin Gahr Date: Tue, 2 Jul 2024 15:45:27 +0200 Subject: [PATCH] fix #202 --- xrft/padding.py | 7 +++++-- xrft/tests/test_padding.py | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/xrft/padding.py b/xrft/padding.py index acb8c45a..cb8ccbdb 100644 --- a/xrft/padding.py +++ b/xrft/padding.py @@ -1,6 +1,7 @@ """ Functions to pad and unpad a N-dimensional regular grid """ + import numpy as np from xarray.core.utils import either_dict_or_kwargs @@ -311,7 +312,9 @@ def _pad_coordinates_callback(vector, iaxis_pad_width, iaxis, kwargs): vector[:n_start] = ( vmin - n_start * spacing + np.linspace(0, spacing * (n_start - 1), n_start) ) - vector[-n_end:] = vmax + spacing + np.linspace(0, spacing * (n_end - 1), n_end) + vector[len(vector) - n_end :] = ( + vmax + spacing + np.linspace(0, spacing * (n_end - 1), n_end) + ) return vector @@ -438,6 +441,6 @@ def _pad_width_to_slice(pad_width, size): A slice object for removing the padded elements of the coordinate array. """ - if type(pad_width) == int: + if isinstance(pad_width, int): pad_width = (pad_width, pad_width) return slice(pad_width[0], size - pad_width[1]) diff --git a/xrft/tests/test_padding.py b/xrft/tests/test_padding.py index c4eb3912..a9d02815 100644 --- a/xrft/tests/test_padding.py +++ b/xrft/tests/test_padding.py @@ -208,6 +208,7 @@ def test_unpad_pop_pad_width_attributes(sample_da_2d, pad_width_arg): ( {"x": 4, "y": 3}, {"x": 4}, + {"x": 0}, {"y": 3}, {"x": (4, 3), "y": 3}, {"x": (4, 3), "y": (5, 3)},