From 481db16ad32a488c9789ff9a7d1b5f55f1112fec Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sat, 15 Oct 2022 18:27:11 -0700 Subject: [PATCH 1/5] Fix doctest warnings, enable errors in CI --- .github/workflows/ci-additional.yaml | 5 ++++- xarray/core/dataarray.py | 18 ++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci-additional.yaml b/.github/workflows/ci-additional.yaml index 7087b43abc3..8f84b021952 100644 --- a/.github/workflows/ci-additional.yaml +++ b/.github/workflows/ci-additional.yaml @@ -72,7 +72,10 @@ jobs: python xarray/util/print_versions.py - name: Run doctests run: | - python -m pytest --doctest-modules xarray --ignore xarray/tests + # Raise an error if there are warnings in the doctests, with `-Werror`. + # This is a trial; if it presents an problem, feel free to remove. + # See https://github.com/pydata/xarray/issues/7164 for more info. + python -m pytest --doctest-modules xarray --ignore xarray/tests -Werror mypy: name: Mypy diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index a7e193c79a0..4dc6a029c6f 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -5261,9 +5261,9 @@ def idxmin( >>> array.min() array(-2) - >>> array.argmin() - - array(4) + >>> array.argmin(...) + {'x': + array(4)} >>> array.idxmin() array('e', dtype='>> array.max() array(2) - >>> array.argmax() - - array(1) + >>> array.argmax(...) + {'x': + array(1)} >>> array.idxmax() array('b', dtype='>> array.min() array(-1) - >>> array.argmin() - - array(2) >>> array.argmin(...) {'x': array(2)} @@ -5555,9 +5552,6 @@ def argmax( >>> array.max() array(3) - >>> array.argmax() - - array(3) >>> array.argmax(...) {'x': array(3)} From 7f5970bb56490a310a6857d6d5ce2b935675e263 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sat, 15 Oct 2022 18:42:23 -0700 Subject: [PATCH 2/5] --- xarray/core/dataarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 4dc6a029c6f..61ee1da661f 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -6025,7 +6025,7 @@ def groupby( >>> da = xr.DataArray( ... np.linspace(0, 1826, num=1827), - ... coords=[pd.date_range("1/1/2000", "31/12/2004", freq="D")], + ... coords=[pd.date_range("2000-01-01", "2004-12-31", freq="D")], ... dims="time", ... ) >>> da From baafef862ca7e21363db4c1f329c0951ea9942d8 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 16 Oct 2022 11:57:13 -0700 Subject: [PATCH 3/5] Remove deprecated doctest example --- xarray/backends/rasterio_.py | 41 ------------------------------------ 1 file changed, 41 deletions(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index d3153eb3e18..a1380d60204 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -189,47 +189,6 @@ def open_rasterio( You can generate 2D coordinates from the file's attributes with:: - >>> from affine import Affine - >>> da = xr.open_rasterio( - ... "https://github.com/rasterio/rasterio/raw/1.2.1/tests/data/RGB.byte.tif" - ... ) - >>> da - - [1703814 values with dtype=uint8] - Coordinates: - * band (band) int64 1 2 3 - * y (y) float64 2.827e+06 2.826e+06 2.826e+06 ... 2.612e+06 2.612e+06 - * x (x) float64 1.021e+05 1.024e+05 1.027e+05 ... 3.389e+05 3.392e+05 - Attributes: - transform: (300.0379266750948, 0.0, 101985.0, 0.0, -300.041782729805... - crs: +init=epsg:32618 - res: (300.0379266750948, 300.041782729805) - is_tiled: 0 - nodatavals: (0.0, 0.0, 0.0) - scales: (1.0, 1.0, 1.0) - offsets: (0.0, 0.0, 0.0) - AREA_OR_POINT: Area - >>> transform = Affine(*da.attrs["transform"]) - >>> transform - Affine(300.0379266750948, 0.0, 101985.0, - 0.0, -300.041782729805, 2826915.0) - >>> nx, ny = da.sizes["x"], da.sizes["y"] - >>> x, y = transform * np.meshgrid(np.arange(nx) + 0.5, np.arange(ny) + 0.5) - >>> x - array([[102135.01896334, 102435.05689001, 102735.09481669, ..., - 338564.90518331, 338864.94310999, 339164.98103666], - [102135.01896334, 102435.05689001, 102735.09481669, ..., - 338564.90518331, 338864.94310999, 339164.98103666], - [102135.01896334, 102435.05689001, 102735.09481669, ..., - 338564.90518331, 338864.94310999, 339164.98103666], - ..., - [102135.01896334, 102435.05689001, 102735.09481669, ..., - 338564.90518331, 338864.94310999, 339164.98103666], - [102135.01896334, 102435.05689001, 102735.09481669, ..., - 338564.90518331, 338864.94310999, 339164.98103666], - [102135.01896334, 102435.05689001, 102735.09481669, ..., - 338564.90518331, 338864.94310999, 339164.98103666]]) - Parameters ---------- filename : str, rasterio.DatasetReader, or rasterio.WarpedVRT From 0bfb6c59ecc76b2bc40be86c12f11943129350b9 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 16 Oct 2022 11:59:06 -0700 Subject: [PATCH 4/5] --- doc/whats-new.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 268b410faa2..ac17a25436a 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -42,6 +42,9 @@ Documentation Internal Changes ~~~~~~~~~~~~~~~~ +- Doctests fail on any warnings (:pull:`7166`) + By `Maximilian Roos `_. + .. _whats-new.2022.10.0: From 9f49afd13edcf3a62787ca0d7ccd37449acbee1d Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 16 Oct 2022 14:05:17 -0700 Subject: [PATCH 5/5] --- xarray/backends/rasterio_.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/xarray/backends/rasterio_.py b/xarray/backends/rasterio_.py index a1380d60204..acd9070320b 100644 --- a/xarray/backends/rasterio_.py +++ b/xarray/backends/rasterio_.py @@ -187,8 +187,6 @@ def open_rasterio( `_ for more information). - You can generate 2D coordinates from the file's attributes with:: - Parameters ---------- filename : str, rasterio.DatasetReader, or rasterio.WarpedVRT