Skip to content

Commit 9bec4e2

Browse files
authored
Add Scipy stubs (pydata#11225)
* update mypy to 1.19.1 * add scipy-stubs to typing deps * add typing to scipy backend * dirty workaround to keep scipy import lazy * restore scipy lazy import test * add test reports to gitignore * pin scipy-stubs for a required fix * fix deprecated variable for codecov * fix more deprecated variable for codecov * fix mypy tests for pytest-mypy-plugins>=4.0.0
1 parent fcf3901 commit 9bec4e2

13 files changed

Lines changed: 182 additions & 128 deletions

.github/workflows/ci-additional.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
- name: Upload mypy coverage to Codecov
135135
uses: codecov/codecov-action@v5.5.2
136136
with:
137-
file: mypy_report/cobertura.xml
137+
files: mypy_report/cobertura.xml
138138
flags: mypy
139139
env_vars: PYTHON_VERSION
140140
name: codecov-umbrella
@@ -179,7 +179,7 @@ jobs:
179179
- name: Upload mypy coverage to Codecov
180180
uses: codecov/codecov-action@v5.5.2
181181
with:
182-
file: mypy_report/cobertura.xml
182+
files: mypy_report/cobertura.xml
183183
flags: mypy-min
184184
env_vars: PYTHON_VERSION
185185
name: codecov-umbrella
@@ -278,7 +278,7 @@ jobs:
278278
- name: Upload pyright coverage to Codecov
279279
uses: codecov/codecov-action@v5.5.2
280280
with:
281-
file: pyright_report/cobertura.xml
281+
files: pyright_report/cobertura.xml
282282
flags: pyright
283283
env_vars: PYTHON_VERSION
284284
name: codecov-umbrella

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ jobs:
170170
env:
171171
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
172172
with:
173-
file: ./coverage.xml
173+
files: ./coverage.xml
174174
flags: unittests
175175
env_vars: RUNNER_OS,PYTHON_VERSION
176176
name: codecov-umbrella

.github/workflows/upstream-dev-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
- name: Upload mypy coverage to Codecov
161161
uses: codecov/codecov-action@v5.5.2
162162
with:
163-
file: mypy_report/cobertura.xml
163+
files: mypy_report/cobertura.xml
164164
flags: mypy
165165
env_vars: PYTHON_VERSION
166166
name: codecov-umbrella

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pip-log.txt
3636
# Unit test / coverage reports
3737
.coverage
3838
.coverage.*
39+
coverage.xml
3940
.tox
4041
nosetests.xml
4142
.cache
@@ -47,6 +48,7 @@ nosetests.xml
4748
.testmon*
4849
.tmontmp/
4950
.pytest_cache
51+
pytest.xml
5052
dask-worker-space/
5153

5254
# asv environments

pixi.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pytest = "*"
205205
pytest-asyncio = "*"
206206
pytest-cov = "*"
207207
pytest-env = "*"
208-
pytest-mypy-plugins = "*"
208+
pytest-mypy-plugins = ">=4.0.0"
209209
pytest-reportlog = "*"
210210
pytest-timeout = "*"
211211
pytest-xdist = "*"
@@ -250,21 +250,24 @@ linkcheck = { cmd = "make linkcheck", cwd = "doc", description = "Check URLs in
250250

251251

252252
[feature.typing.dependencies]
253-
mypy = "==1.18.1"
253+
mypy = "==1.19.1"
254254
pyright = "*"
255255
hypothesis = "*"
256256
lxml = "*"
257257
pandas-stubs = "<=2.3.3.251219"
258+
scipy-stubs = ">=1.17.1.2"
258259
types-colorama = "*"
259260
types-docutils = "*"
261+
types-decorator = "*"
262+
types-networkx = "*"
263+
types-openpyxl = "*"
260264
types-psutil = "*"
261265
types-Pygments = "*"
262266
types-python-dateutil = "*"
263267
types-pytz = "*"
264268
types-PyYAML = "*"
265269
types-requests = "*"
266270
types-setuptools = "*"
267-
types-openpyxl = "*"
268271
typing_extensions = "*"
269272
pip = "*"
270273

pyproject.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,39 @@ viz = ["cartopy>=0.24", "matplotlib>=3.10", "nc-time-axis", "seaborn"]
5151
types = [
5252
"pandas-stubs",
5353
"scipy-stubs",
54-
"types-PyYAML",
55-
"types-Pygments",
5654
"types-colorama",
5755
"types-decorator",
5856
"types-defusedxml",
5957
"types-docutils",
6058
"types-networkx",
59+
"types-openpyxl",
6160
"types-pexpect",
6261
"types-psutil",
6362
"types-pycurl",
64-
"types-openpyxl",
63+
"types-Pygments",
6564
"types-python-dateutil",
6665
"types-pytz",
66+
"types-PyYAML",
6767
"types-requests",
6868
"types-setuptools",
69+
"types-xlrd",
6970
]
7071

7172
[dependency-groups]
7273
dev = [
7374
"hypothesis",
7475
"jinja2",
75-
"mypy==1.18.1",
76+
"mypy==1.19.1",
7677
"pre-commit",
7778
"pytest",
7879
"pytest-cov",
7980
"pytest-env",
80-
"pytest-mypy-plugins",
81+
"pytest-mypy-plugins>=4.0.0",
8182
"pytest-timeout",
8283
"pytest-xdist",
8384
"pytest-asyncio",
8485
"pytz",
85-
"ruff>=0.8.0",
86+
"ruff>=0.15.0",
8687
"sphinx",
8788
"sphinx_autosummary_accessors",
8889
"xarray[complete,types]",
@@ -158,7 +159,6 @@ module = [
158159
"pooch.*",
159160
"pyarrow.*",
160161
"pydap.*",
161-
"scipy.*",
162162
"seaborn.*",
163163
"setuptools",
164164
"sparse.*",
@@ -176,6 +176,7 @@ module = [
176176
[[tool.mypy.overrides]]
177177
check_untyped_defs = true
178178
module = [
179+
"xarray.backends.scipy_",
179180
"xarray.core.accessor_dt",
180181
"xarray.core.accessor_str",
181182
"xarray.structure.alignment",

xarray/backends/common.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Any,
1313
ClassVar,
1414
Self,
15+
TypeAlias,
1516
TypeVar,
1617
Union,
1718
overload,
@@ -381,7 +382,7 @@ def __exit__(self, exception_type, exception_value, traceback):
381382
self.close()
382383

383384

384-
T_PathFileOrDataStore = (
385+
T_PathFileOrDataStore: TypeAlias = (
385386
str | os.PathLike[Any] | ReadBuffer | bytes | memoryview | AbstractDataStore
386387
)
387388

@@ -776,12 +777,7 @@ def __repr__(self) -> str:
776777

777778
def open_dataset(
778779
self,
779-
filename_or_obj: str
780-
| os.PathLike[Any]
781-
| ReadBuffer
782-
| bytes
783-
| memoryview
784-
| AbstractDataStore,
780+
filename_or_obj: T_PathFileOrDataStore,
785781
*,
786782
drop_variables: str | Iterable[str] | None = None,
787783
) -> Dataset:
@@ -793,12 +789,7 @@ def open_dataset(
793789

794790
def guess_can_open(
795791
self,
796-
filename_or_obj: str
797-
| os.PathLike[Any]
798-
| ReadBuffer
799-
| bytes
800-
| memoryview
801-
| AbstractDataStore,
792+
filename_or_obj: T_PathFileOrDataStore,
802793
) -> bool:
803794
"""
804795
Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`.
@@ -808,12 +799,7 @@ def guess_can_open(
808799

809800
def open_datatree(
810801
self,
811-
filename_or_obj: str
812-
| os.PathLike[Any]
813-
| ReadBuffer
814-
| bytes
815-
| memoryview
816-
| AbstractDataStore,
802+
filename_or_obj: T_PathFileOrDataStore,
817803
*,
818804
drop_variables: str | Iterable[str] | None = None,
819805
) -> DataTree:
@@ -827,12 +813,7 @@ def open_datatree(
827813

828814
def open_groups_as_dict(
829815
self,
830-
filename_or_obj: str
831-
| os.PathLike[Any]
832-
| ReadBuffer
833-
| bytes
834-
| memoryview
835-
| AbstractDataStore,
816+
filename_or_obj: T_PathFileOrDataStore,
836817
*,
837818
drop_variables: str | Iterable[str] | None = None,
838819
) -> dict[str, Dataset]:

0 commit comments

Comments
 (0)