Skip to content

Commit 8c21376

Browse files
authored
Start a list of modules which require typing (#8198)
* Start a list of modules which require typing Notes inline. Just one module so far!
1 parent 1d2e5c6 commit 8c21376

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ show_error_context = true
7979
warn_redundant_casts = true
8080
warn_unused_ignores = true
8181

82-
# Most of the numerical computing stack doesn't have type annotations yet.
82+
# Much of the numerical computing stack doesn't have type annotations yet.
8383
[[tool.mypy.overrides]]
8484
ignore_missing_imports = true
8585
module = [
@@ -118,6 +118,15 @@ module = [
118118
"numpy.exceptions.*", # remove once support for `numpy<2.0` has been dropped
119119
]
120120

121+
# Gradually we want to add more modules to this list, ratcheting up our total
122+
# coverage. Once a module is here, functions require annotations in order to
123+
# pass mypy. It would be especially useful to have tests here, because without
124+
# annotating test functions, we don't have a great way of testing our type
125+
# annotations — even with just `-> None` is sufficient for mypy to check them.
126+
[[tool.mypy.overrides]]
127+
disallow_untyped_defs = true
128+
module = ["xarray.core.rolling_exp"]
129+
121130
[tool.ruff]
122131
builtins = ["ellipsis"]
123132
exclude = [

xarray/core/rolling_exp.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
from xarray.core.options import _get_keep_attrs
1010
from xarray.core.pdcompat import count_not_none
1111
from xarray.core.pycompat import is_duck_dask_array
12-
from xarray.core.types import T_DataWithCoords
12+
from xarray.core.types import T_DataWithCoords, T_DuckArray
1313

1414

15-
def _get_alpha(com=None, span=None, halflife=None, alpha=None):
15+
def _get_alpha(
16+
com: float | None = None,
17+
span: float | None = None,
18+
halflife: float | None = None,
19+
alpha: float | None = None,
20+
) -> float:
1621
# pandas defines in terms of com (converting to alpha in the algo)
1722
# so use its function to get a com and then convert to alpha
1823

1924
com = _get_center_of_mass(com, span, halflife, alpha)
2025
return 1 / (1 + com)
2126

2227

23-
def move_exp_nanmean(array, *, axis, alpha):
28+
def move_exp_nanmean(array: T_DuckArray, *, axis: int, alpha: float) -> np.ndarray:
2429
if is_duck_dask_array(array):
2530
raise TypeError("rolling_exp is not currently support for dask-like arrays")
2631
import numbagg
@@ -32,15 +37,20 @@ def move_exp_nanmean(array, *, axis, alpha):
3237
return numbagg.move_exp_nanmean(array, axis=axis, alpha=alpha)
3338

3439

35-
def move_exp_nansum(array, *, axis, alpha):
40+
def move_exp_nansum(array: T_DuckArray, *, axis: int, alpha: float) -> np.ndarray:
3641
if is_duck_dask_array(array):
3742
raise TypeError("rolling_exp is not currently supported for dask-like arrays")
3843
import numbagg
3944

4045
return numbagg.move_exp_nansum(array, axis=axis, alpha=alpha)
4146

4247

43-
def _get_center_of_mass(comass, span, halflife, alpha):
48+
def _get_center_of_mass(
49+
comass: float | None,
50+
span: float | None,
51+
halflife: float | None,
52+
alpha: float | None,
53+
) -> float:
4454
"""
4555
Vendored from pandas.core.window.common._get_center_of_mass
4656

0 commit comments

Comments
 (0)