Skip to content

Commit b98ab3a

Browse files
committed
Use "length" instead of "count" to refer to the length of a coordinate
1 parent a2b235c commit b98ab3a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

xarray/tests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,18 @@ def create_test_data(seed=None, add_attrs=True):
231231
return obj
232232

233233

234-
def get_expected_rolling_indices(count, window, center, pad, stride=1):
234+
def get_expected_rolling_indices(length, window, center, pad, stride=1):
235235
# Without padding, we lose (window-1) items from the index, either from the beginning
236236
# (without centering) or from the beginning and end (with centering)
237237
if pad:
238238
start_index = 0
239-
end_index = count
239+
end_index = length
240240
elif center:
241241
start_index = window // 2 # 10 -> 5, 9 -> 4
242-
end_index = count - (window - 1) // 2 # 10 -> 4, 9 -> 4
242+
end_index = length - (window - 1) // 2 # 10 -> 4, 9 -> 4
243243
else:
244244
start_index = window - 1
245-
end_index = count
245+
end_index = length
246246

247247
expected_index = np.arange(start_index, end_index, stride)
248248

xarray/tests/test_dataarray.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6617,11 +6617,11 @@ def test_rolling_wrapped_bottleneck_center_pad(da, name, center, pad):
66176617
pytest.importorskip("bottleneck", minversion="1.1")
66186618

66196619
window = 7
6620-
count = len(da["time"])
6620+
length = len(da["time"])
66216621
rolling_obj = da.rolling(time=7, center=center, pad=pad)
66226622
actual = getattr(rolling_obj, name)()["time"]
66236623

6624-
expected_index = get_expected_rolling_indices(count, window, center, pad)
6624+
expected_index = get_expected_rolling_indices(length, window, center, pad)
66256625
expected = da["time"][expected_index]
66266626

66276627
assert_equal(actual, expected)
@@ -6712,10 +6712,10 @@ def test_rolling_pandas_compat(center, pad, window, min_periods):
67126712
@pytest.mark.parametrize("center", (True, False))
67136713
@pytest.mark.parametrize("window", (2, 3, 4))
67146714
def test_rolling_construct(center, window):
6715-
count = 10
6716-
s = pd.Series(np.arange(count))
6715+
length = 10
6716+
s = pd.Series(np.arange(length))
67176717
da = DataArray.from_series(s)
6718-
da = da.assign_coords(time=("index", np.arange(1, count + 1)))
6718+
da = da.assign_coords(time=("index", np.arange(1, length + 1)))
67196719

67206720
s_rolling = s.rolling(window, center=center, min_periods=1).mean()
67216721
da_rolling = da.rolling(index=window, center=center, min_periods=1)
@@ -6741,7 +6741,7 @@ def test_rolling_construct(center, window):
67416741
da_rolling_mean = da_rolling.construct("window", stride=2).mean("window")
67426742

67436743
expected_index = get_expected_rolling_indices(
6744-
count, window, center, pad=False, stride=2
6744+
length, window, center, pad=False, stride=2
67456745
)
67466746

67476747
assert da_rolling_mean.sizes["index"] == len(expected_index)

0 commit comments

Comments
 (0)