From 379bf9d072ec3e9244e0b8c7555931dcf5406810 Mon Sep 17 00:00:00 2001 From: Richard Kleijn Date: Sun, 3 Jul 2022 10:47:10 +0200 Subject: [PATCH] fix some mypy errors --- xarray/core/rolling.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index 916fabe42ac..55901d56424 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -4,7 +4,7 @@ import itertools import math import warnings -from collections.abc import Hashable, Iterator, Mapping +from collections.abc import Hashable, Iterator, Mapping, Sequence from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar import numpy as np @@ -467,9 +467,8 @@ def reduce( obj, rolling_dim, keep_attrs=keep_attrs, fill_value=fillna ) - result = windows.reduce( - func, dim=list(rolling_dim.values()), keep_attrs=keep_attrs, **kwargs - ) + dim: Sequence[Hashable] = list(rolling_dim.values()) + result = windows.reduce(func, dim=dim, keep_attrs=keep_attrs, **kwargs) # Find valid windows based on count. counts = self._counts(keep_attrs=False) @@ -486,6 +485,7 @@ def _counts(self, keep_attrs: bool | None) -> DataArray: # array is faster to be reduced than object array. # The use of skipna==False is also faster since it does not need to # copy the strided array. + dim: Sequence[Hashable] = list(rolling_dim.values()) counts = ( self.obj.notnull(keep_attrs=keep_attrs) .rolling( @@ -493,7 +493,7 @@ def _counts(self, keep_attrs: bool | None) -> DataArray: center={d: self.center[i] for i, d in enumerate(self.dim)}, ) .construct(rolling_dim, fill_value=False, keep_attrs=keep_attrs) - .sum(dim=list(rolling_dim.values()), skipna=False, keep_attrs=keep_attrs) + .sum(dim=dim, skipna=False, keep_attrs=keep_attrs) ) return counts