Skip to content

Commit cafab46

Browse files
authored
Blacken the doctest code in docstrings (#3857)
* fix a few erroneous doctest blocks * blacken the doctest code * manually remove the trailing comma from doctest lines
1 parent ae03616 commit cafab46

21 files changed

+307
-244
lines changed

xarray/backends/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,8 @@ def save_mfdataset(
11961196
11971197
Save a dataset into one netCDF per year of data:
11981198
1199-
>>> years, datasets = zip(*ds.groupby('time.year'))
1200-
>>> paths = ['%s.nc' % y for y in years]
1199+
>>> years, datasets = zip(*ds.groupby("time.year"))
1200+
>>> paths = ["%s.nc" % y for y in years]
12011201
>>> xr.save_mfdataset(datasets, paths)
12021202
"""
12031203
if mode == "w" and len(set(paths)) < len(paths):

xarray/coding/cftime_offsets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ def cftime_range(
938938
This function returns a ``CFTimeIndex``, populated with ``cftime.datetime``
939939
objects associated with the specified calendar type, e.g.
940940
941-
>>> xr.cftime_range(start='2000', periods=6, freq='2MS', calendar='noleap')
941+
>>> xr.cftime_range(start="2000", periods=6, freq="2MS", calendar="noleap")
942942
CFTimeIndex([2000-01-01 00:00:00, 2000-03-01 00:00:00, 2000-05-01 00:00:00,
943943
2000-07-01 00:00:00, 2000-09-01 00:00:00, 2000-11-01 00:00:00],
944944
dtype='object')

xarray/coding/cftimeindex.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -269,29 +269,32 @@ def _partial_date_slice(self, resolution, parsed):
269269
>>> from cftime import DatetimeNoLeap
270270
>>> import pandas as pd
271271
>>> import xarray as xr
272-
>>> da = xr.DataArray([1, 2],
273-
coords=[[DatetimeNoLeap(2001, 1, 1),
274-
DatetimeNoLeap(2001, 2, 1)]],
275-
dims=['time'])
276-
>>> da.sel(time='2001-01-01')
272+
>>> da = xr.DataArray(
273+
... [1, 2],
274+
... coords=[[DatetimeNoLeap(2001, 1, 1), DatetimeNoLeap(2001, 2, 1)]],
275+
... dims=["time"],
276+
... )
277+
>>> da.sel(time="2001-01-01")
277278
<xarray.DataArray (time: 1)>
278279
array([1])
279280
Coordinates:
280281
* time (time) object 2001-01-01 00:00:00
281-
>>> da = xr.DataArray([1, 2],
282-
coords=[[pd.Timestamp(2001, 1, 1),
283-
pd.Timestamp(2001, 2, 1)]],
284-
dims=['time'])
285-
>>> da.sel(time='2001-01-01')
282+
>>> da = xr.DataArray(
283+
... [1, 2],
284+
... coords=[[pd.Timestamp(2001, 1, 1), pd.Timestamp(2001, 2, 1)]],
285+
... dims=["time"],
286+
... )
287+
>>> da.sel(time="2001-01-01")
286288
<xarray.DataArray ()>
287289
array(1)
288290
Coordinates:
289291
time datetime64[ns] 2001-01-01
290-
>>> da = xr.DataArray([1, 2],
291-
coords=[[pd.Timestamp(2001, 1, 1, 1),
292-
pd.Timestamp(2001, 2, 1)]],
293-
dims=['time'])
294-
>>> da.sel(time='2001-01-01')
292+
>>> da = xr.DataArray(
293+
... [1, 2],
294+
... coords=[[pd.Timestamp(2001, 1, 1, 1), pd.Timestamp(2001, 2, 1)]],
295+
... dims=["time"],
296+
... )
297+
>>> da.sel(time="2001-01-01")
295298
<xarray.DataArray (time: 1)>
296299
array([1])
297300
Coordinates:
@@ -423,10 +426,10 @@ def shift(self, n, freq):
423426
424427
Examples
425428
--------
426-
>>> index = xr.cftime_range('2000', periods=1, freq='M')
429+
>>> index = xr.cftime_range("2000", periods=1, freq="M")
427430
>>> index
428431
CFTimeIndex([2000-01-31 00:00:00], dtype='object')
429-
>>> index.shift(1, 'M')
432+
>>> index.shift(1, "M")
430433
CFTimeIndex([2000-02-29 00:00:00], dtype='object')
431434
"""
432435
from .cftime_offsets import to_offset
@@ -511,7 +514,7 @@ def to_datetimeindex(self, unsafe=False):
511514
Examples
512515
--------
513516
>>> import xarray as xr
514-
>>> times = xr.cftime_range('2000', periods=2, calendar='gregorian')
517+
>>> times = xr.cftime_range("2000", periods=2, calendar="gregorian")
515518
>>> times
516519
CFTimeIndex([2000-01-01 00:00:00, 2000-01-02 00:00:00], dtype='object')
517520
>>> times.to_datetimeindex()
@@ -550,9 +553,10 @@ def strftime(self, date_format):
550553
551554
Examples
552555
--------
553-
>>> rng = xr.cftime_range(start='2000', periods=5, freq='2MS',
554-
... calendar='noleap')
555-
>>> rng.strftime('%B %d, %Y, %r')
556+
>>> rng = xr.cftime_range(
557+
... start="2000", periods=5, freq="2MS", calendar="noleap"
558+
... )
559+
>>> rng.strftime("%B %d, %Y, %r")
556560
Index(['January 01, 2000, 12:00:00 AM', 'March 01, 2000, 12:00:00 AM',
557561
'May 01, 2000, 12:00:00 AM', 'July 01, 2000, 12:00:00 AM',
558562
'September 01, 2000, 12:00:00 AM'],

xarray/coding/strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class StackedBytesArray(indexing.ExplicitlyIndexedNDArrayMixin):
201201
"""Wrapper around array-like objects to create a new indexable object where
202202
values, when accessed, are automatically stacked along the last dimension.
203203
204-
>>> StackedBytesArray(np.array(['a', 'b', 'c']))[:]
204+
>>> StackedBytesArray(np.array(["a", "b", "c"]))[:]
205205
array('abc',
206206
dtype='|S3')
207207
"""

xarray/conventions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class NativeEndiannessArray(indexing.ExplicitlyIndexedNDArrayMixin):
1919
big endian) into native endianness, so they can be used with Cython
2020
functions, such as those found in bottleneck and pandas.
2121
22-
>>> x = np.arange(5, dtype='>i2')
22+
>>> x = np.arange(5, dtype=">i2")
2323
2424
>>> x.dtype
2525
dtype('>i2')
@@ -50,7 +50,7 @@ class BoolTypeArray(indexing.ExplicitlyIndexedNDArrayMixin):
5050
This is useful for decoding boolean arrays from integer typed netCDF
5151
variables.
5252
53-
>>> x = np.array([1, 0, 1, 1, 0], dtype='i1')
53+
>>> x = np.array([1, 0, 1, 1, 0], dtype="i1")
5454
5555
>>> x.dtype
5656
dtype('>i2')

xarray/core/accessor_dt.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ class DatetimeAccessor(Properties):
250250
---------
251251
>>> import xarray as xr
252252
>>> import pandas as pd
253-
>>> dates = pd.date_range(start='2000/01/01', freq='D', periods=10)
254-
>>> ts = xr.DataArray(dates, dims=('time'))
253+
>>> dates = pd.date_range(start="2000/01/01", freq="D", periods=10)
254+
>>> ts = xr.DataArray(dates, dims=("time"))
255255
>>> ts
256256
<xarray.DataArray (time: 10)>
257257
array(['2000-01-01T00:00:00.000000000', '2000-01-02T00:00:00.000000000',
@@ -296,8 +296,8 @@ def strftime(self, date_format):
296296
297297
Examples
298298
--------
299-
>>> rng = xr.Dataset({'time': datetime.datetime(2000, 1, 1)})
300-
>>> rng['time'].dt.strftime('%B %d, %Y, %r')
299+
>>> rng = xr.Dataset({"time": datetime.datetime(2000, 1, 1)})
300+
>>> rng["time"].dt.strftime("%B %d, %Y, %r")
301301
<xarray.DataArray 'strftime' ()>
302302
array('January 01, 2000, 12:00:00 AM', dtype=object)
303303
"""
@@ -400,7 +400,7 @@ class TimedeltaAccessor(Properties):
400400
>>> import pandas as pd
401401
>>> import xarray as xr
402402
>>> dates = pd.timedelta_range(start="1 day", freq="6H", periods=20)
403-
>>> ts = xr.DataArray(dates, dims=('time'))
403+
>>> ts = xr.DataArray(dates, dims=("time"))
404404
>>> ts
405405
<xarray.DataArray (time: 20)>
406406
array([ 86400000000000, 108000000000000, 129600000000000, 151200000000000,

xarray/core/accessor_str.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class StringAccessor:
6767
Similar to pandas, fields can be accessed through the `.str` attribute
6868
for applicable DataArrays.
6969
70-
>>> da = xr.DataArray(['some', 'text', 'in', 'an', 'array'])
70+
>>> da = xr.DataArray(["some", "text", "in", "an", "array"])
7171
>>> ds.str.len()
7272
<xarray.DataArray (dim_0: 5)>
7373
array([4, 4, 2, 2, 5])

xarray/core/alignment.py

+20-14
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ def align(
121121
--------
122122
123123
>>> import xarray as xr
124-
>>> x = xr.DataArray([[25, 35], [10, 24]], dims=('lat', 'lon'),
125-
... coords={'lat': [35., 40.], 'lon': [100., 120.]})
126-
>>> y = xr.DataArray([[20, 5], [7, 13]], dims=('lat', 'lon'),
127-
... coords={'lat': [35., 42.], 'lon': [100., 120.]})
124+
>>> x = xr.DataArray(
125+
... [[25, 35], [10, 24]],
126+
... dims=("lat", "lon"),
127+
... coords={"lat": [35.0, 40.0], "lon": [100.0, 120.0]},
128+
... )
129+
>>> y = xr.DataArray(
130+
... [[20, 5], [7, 13]],
131+
... dims=("lat", "lon"),
132+
... coords={"lat": [35.0, 42.0], "lon": [100.0, 120.0]},
133+
... )
128134
129135
>>> x
130136
<xarray.DataArray (lat: 2, lon: 2)>
@@ -156,7 +162,7 @@ def align(
156162
* lat (lat) float64 35.0
157163
* lon (lon) float64 100.0 120.0
158164
159-
>>> a, b = xr.align(x, y, join='outer')
165+
>>> a, b = xr.align(x, y, join="outer")
160166
>>> a
161167
<xarray.DataArray (lat: 3, lon: 2)>
162168
array([[25., 35.],
@@ -174,7 +180,7 @@ def align(
174180
* lat (lat) float64 35.0 40.0 42.0
175181
* lon (lon) float64 100.0 120.0
176182
177-
>>> a, b = xr.align(x, y, join='outer', fill_value=-999)
183+
>>> a, b = xr.align(x, y, join="outer", fill_value=-999)
178184
>>> a
179185
<xarray.DataArray (lat: 3, lon: 2)>
180186
array([[ 25, 35],
@@ -192,7 +198,7 @@ def align(
192198
* lat (lat) float64 35.0 40.0 42.0
193199
* lon (lon) float64 100.0 120.0
194200
195-
>>> a, b = xr.align(x, y, join='left')
201+
>>> a, b = xr.align(x, y, join="left")
196202
>>> a
197203
<xarray.DataArray (lat: 2, lon: 2)>
198204
array([[25, 35],
@@ -208,7 +214,7 @@ def align(
208214
* lat (lat) float64 35.0 40.0
209215
* lon (lon) float64 100.0 120.0
210216
211-
>>> a, b = xr.align(x, y, join='right')
217+
>>> a, b = xr.align(x, y, join="right")
212218
>>> a
213219
<xarray.DataArray (lat: 2, lon: 2)>
214220
array([[25., 35.],
@@ -224,13 +230,13 @@ def align(
224230
* lat (lat) float64 35.0 42.0
225231
* lon (lon) float64 100.0 120.0
226232
227-
>>> a, b = xr.align(x, y, join='exact')
233+
>>> a, b = xr.align(x, y, join="exact")
228234
Traceback (most recent call last):
229235
...
230236
"indexes along dimension {!r} are not equal".format(dim)
231237
ValueError: indexes along dimension 'lat' are not equal
232238
233-
>>> a, b = xr.align(x, y, join='override')
239+
>>> a, b = xr.align(x, y, join="override")
234240
>>> a
235241
<xarray.DataArray (lat: 2, lon: 2)>
236242
array([[25, 35],
@@ -674,8 +680,8 @@ def broadcast(*args, exclude=None):
674680
675681
Broadcast two data arrays against one another to fill out their dimensions:
676682
677-
>>> a = xr.DataArray([1, 2, 3], dims='x')
678-
>>> b = xr.DataArray([5, 6], dims='y')
683+
>>> a = xr.DataArray([1, 2, 3], dims="x")
684+
>>> b = xr.DataArray([5, 6], dims="y")
679685
>>> a
680686
<xarray.DataArray (x: 3)>
681687
array([1, 2, 3])
@@ -706,8 +712,8 @@ def broadcast(*args, exclude=None):
706712
707713
Fill out the dimensions of all data variables in a dataset:
708714
709-
>>> ds = xr.Dataset({'a': a, 'b': b})
710-
>>> ds2, = xr.broadcast(ds) # use tuple unpacking to extract one dataset
715+
>>> ds = xr.Dataset({"a": a, "b": b})
716+
>>> (ds2,) = xr.broadcast(ds) # use tuple unpacking to extract one dataset
711717
>>> ds2
712718
<xarray.Dataset>
713719
Dimensions: (x: 3, y: 2)

xarray/core/combine.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def combine_nested(
412412
precipitation (x, y) float64 5.904 2.453 3.404 ...
413413
414414
>>> ds_grid = [[x1y1, x1y2], [x2y1, x2y2]]
415-
>>> combined = xr.combine_nested(ds_grid, concat_dim=['x', 'y'])
415+
>>> combined = xr.combine_nested(ds_grid, concat_dim=["x", "y"])
416416
<xarray.Dataset>
417417
Dimensions: (x: 4, y: 4)
418418
Dimensions without coordinates: x, y
@@ -441,7 +441,7 @@ def combine_nested(
441441
precipitation (t) float64 5.904 2.453 3.404 ...
442442
443443
>>> ds_grid = [[t1temp, t1precip], [t2temp, t2precip]]
444-
>>> combined = xr.combine_nested(ds_grid, concat_dim=['t', None])
444+
>>> combined = xr.combine_nested(ds_grid, concat_dim=["t", None])
445445
<xarray.Dataset>
446446
Dimensions: (t: 10)
447447
Dimensions without coordinates: t
@@ -650,7 +650,7 @@ def combine_by_coords(
650650
temperature (y, x) float64 1.654 10.63 7.015 nan ... nan 12.46 2.22 15.96
651651
precipitation (y, x) float64 0.2136 0.9974 0.7603 ... 0.6125 0.4654 0.5953
652652
653-
>>> xr.combine_by_coords([x3, x1], join='override')
653+
>>> xr.combine_by_coords([x3, x1], join="override")
654654
<xarray.Dataset>
655655
Dimensions: (x: 3, y: 4)
656656
Coordinates:

0 commit comments

Comments
 (0)