Skip to content

Commit 24d038f

Browse files
authored
Fix doctest warnings, enable errors in CI (#7166)
* Fix doctest warnings, enable errors in CI * Remove deprecated doctest example
1 parent 93f1ba2 commit 24d038f

File tree

4 files changed

+13
-56
lines changed

4 files changed

+13
-56
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ jobs:
7272
python xarray/util/print_versions.py
7373
- name: Run doctests
7474
run: |
75-
python -m pytest --doctest-modules xarray --ignore xarray/tests
75+
# Raise an error if there are warnings in the doctests, with `-Werror`.
76+
# This is a trial; if it presents an problem, feel free to remove.
77+
# See https://github.com/pydata/xarray/issues/7164 for more info.
78+
python -m pytest --doctest-modules xarray --ignore xarray/tests -Werror
7679
7780
mypy:
7881
name: Mypy

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Documentation
5050

5151
Internal Changes
5252
~~~~~~~~~~~~~~~~
53+
- Doctests fail on any warnings (:pull:`7166`)
54+
By `Maximilian Roos <https://github.com/max-sixty>`_.
55+
5356

5457

5558
.. _whats-new.2022.10.0:

xarray/backends/rasterio_.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -187,49 +187,6 @@ def open_rasterio(
187187
<http://web.archive.org/web/20160326194152/http://remotesensing.org/geotiff/spec/geotiff2.5.html#2.5.2>`_
188188
for more information).
189189
190-
You can generate 2D coordinates from the file's attributes with::
191-
192-
>>> from affine import Affine
193-
>>> da = xr.open_rasterio(
194-
... "https://github.com/rasterio/rasterio/raw/1.2.1/tests/data/RGB.byte.tif"
195-
... )
196-
>>> da
197-
<xarray.DataArray (band: 3, y: 718, x: 791)>
198-
[1703814 values with dtype=uint8]
199-
Coordinates:
200-
* band (band) int64 1 2 3
201-
* y (y) float64 2.827e+06 2.826e+06 2.826e+06 ... 2.612e+06 2.612e+06
202-
* x (x) float64 1.021e+05 1.024e+05 1.027e+05 ... 3.389e+05 3.392e+05
203-
Attributes:
204-
transform: (300.0379266750948, 0.0, 101985.0, 0.0, -300.041782729805...
205-
crs: +init=epsg:32618
206-
res: (300.0379266750948, 300.041782729805)
207-
is_tiled: 0
208-
nodatavals: (0.0, 0.0, 0.0)
209-
scales: (1.0, 1.0, 1.0)
210-
offsets: (0.0, 0.0, 0.0)
211-
AREA_OR_POINT: Area
212-
>>> transform = Affine(*da.attrs["transform"])
213-
>>> transform
214-
Affine(300.0379266750948, 0.0, 101985.0,
215-
0.0, -300.041782729805, 2826915.0)
216-
>>> nx, ny = da.sizes["x"], da.sizes["y"]
217-
>>> x, y = transform * np.meshgrid(np.arange(nx) + 0.5, np.arange(ny) + 0.5)
218-
>>> x
219-
array([[102135.01896334, 102435.05689001, 102735.09481669, ...,
220-
338564.90518331, 338864.94310999, 339164.98103666],
221-
[102135.01896334, 102435.05689001, 102735.09481669, ...,
222-
338564.90518331, 338864.94310999, 339164.98103666],
223-
[102135.01896334, 102435.05689001, 102735.09481669, ...,
224-
338564.90518331, 338864.94310999, 339164.98103666],
225-
...,
226-
[102135.01896334, 102435.05689001, 102735.09481669, ...,
227-
338564.90518331, 338864.94310999, 339164.98103666],
228-
[102135.01896334, 102435.05689001, 102735.09481669, ...,
229-
338564.90518331, 338864.94310999, 339164.98103666],
230-
[102135.01896334, 102435.05689001, 102735.09481669, ...,
231-
338564.90518331, 338864.94310999, 339164.98103666]])
232-
233190
Parameters
234191
----------
235192
filename : str, rasterio.DatasetReader, or rasterio.WarpedVRT

xarray/core/dataarray.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5261,9 +5261,9 @@ def idxmin(
52615261
>>> array.min()
52625262
<xarray.DataArray ()>
52635263
array(-2)
5264-
>>> array.argmin()
5265-
<xarray.DataArray ()>
5266-
array(4)
5264+
>>> array.argmin(...)
5265+
{'x': <xarray.DataArray ()>
5266+
array(4)}
52675267
>>> array.idxmin()
52685268
<xarray.DataArray 'x' ()>
52695269
array('e', dtype='<U1')
@@ -5357,9 +5357,9 @@ def idxmax(
53575357
>>> array.max()
53585358
<xarray.DataArray ()>
53595359
array(2)
5360-
>>> array.argmax()
5361-
<xarray.DataArray ()>
5362-
array(1)
5360+
>>> array.argmax(...)
5361+
{'x': <xarray.DataArray ()>
5362+
array(1)}
53635363
>>> array.idxmax()
53645364
<xarray.DataArray 'x' ()>
53655365
array('b', dtype='<U1')
@@ -5450,9 +5450,6 @@ def argmin(
54505450
>>> array.min()
54515451
<xarray.DataArray ()>
54525452
array(-1)
5453-
>>> array.argmin()
5454-
<xarray.DataArray ()>
5455-
array(2)
54565453
>>> array.argmin(...)
54575454
{'x': <xarray.DataArray ()>
54585455
array(2)}
@@ -5555,9 +5552,6 @@ def argmax(
55555552
>>> array.max()
55565553
<xarray.DataArray ()>
55575554
array(3)
5558-
>>> array.argmax()
5559-
<xarray.DataArray ()>
5560-
array(3)
55615555
>>> array.argmax(...)
55625556
{'x': <xarray.DataArray ()>
55635557
array(3)}

0 commit comments

Comments
 (0)