Skip to content

Commit 5a60aac

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6598b3a commit 5a60aac

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

xarray/coding/times.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,21 +1373,21 @@ class CFDatetimeCoder(VariableCoder):
13731373
on_error : str, optional
13741374
What to do if there is an error when attempting to decode
13751375
a time variable. Options are: "raise", "warn", "ignore".
1376-
Defaults to "raise".
1376+
Defaults to "raise".
13771377
"""
13781378

13791379
def __init__(
13801380
self,
13811381
use_cftime: bool | None = None,
13821382
time_unit: PDDatetimeUnitOptions = "ns",
1383-
on_error: str = "raise"
1383+
on_error: str = "raise",
13841384
) -> None:
13851385
self.use_cftime = use_cftime
13861386
self.time_unit = time_unit
13871387
if on_error in {"raise", "warn", "ignore"}:
13881388
self.on_error = on_error
13891389
else:
1390-
raise ValueError('on_error must be one of "raise", "warn", "ignore")')
1390+
raise ValueError('on_error must be one of "raise", "warn", "ignore")')
13911391

13921392
def encode(self, variable: Variable, name: T_Name = None) -> Variable:
13931393
if np.issubdtype(variable.dtype, np.datetime64) or contains_cftime_datetimes(

xarray/tests/test_coding_times.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,15 +2230,14 @@ def test_roundtrip_empty_datetime64_array(time_unit: PDDatetimeUnitOptions) -> N
22302230
assert_identical(variable, roundtripped)
22312231
assert roundtripped.dtype == variable.dtype
22322232

2233+
22332234
@requires_cftime
22342235
def test_on_error_raises():
22352236
"""
22362237
By default, decoding errors should raise
22372238
"""
22382239
array = np.array([0, 1, 2], dtype=np.dtype("int64"))
2239-
encoded = Variable(["time"],
2240-
array,
2241-
attrs={"units": "ms since 00:00:00"})
2240+
encoded = Variable(["time"], array, attrs={"units": "ms since 00:00:00"})
22422241

22432242
# default is "raise"
22442243
coder = CFDatetimeCoder()
@@ -2252,15 +2251,14 @@ def test_on_error_raises():
22522251
with pytest.raises(ValueError):
22532252
coder.decode(encoded)
22542253

2254+
22552255
@requires_cftime
22562256
def test_on_error_ignore():
22572257
"""
22582258
If on_error="ignore", no change.
22592259
"""
22602260
array = np.array([0, 1, 2], dtype=np.dtype("int64"))
2261-
encoded = Variable(["time"],
2262-
array,
2263-
attrs={"units": "ms since 00:00:00"})
2261+
encoded = Variable(["time"], array, attrs={"units": "ms since 00:00:00"})
22642262

22652263
coder = CFDatetimeCoder(on_error="ignore")
22662264

@@ -2269,20 +2267,19 @@ def test_on_error_ignore():
22692267
# it shouldn't have changed the variable
22702268
assert decoded is encoded
22712269

2270+
22722271
@requires_cftime
22732272
def test_on_error_warn():
22742273
"""
22752274
If on_error="warn", no change, with a warning.
22762275
"""
22772276
array = np.array([0, 1, 2], dtype=np.dtype("int64"))
2278-
encoded = Variable(["time"],
2279-
array,
2280-
attrs={"units": "ms since 00:00:00"})
2277+
encoded = Variable(["time"], array, attrs={"units": "ms since 00:00:00"})
22812278

22822279
coder = CFDatetimeCoder(on_error="warn")
22832280

22842281
with pytest.warns(UserWarning, match="unable to decode time units"):
22852282
decoded = coder.decode(encoded)
22862283

2287-
# it shouldn't have changed the variable
2284+
# it shouldn't have changed the variable
22882285
assert decoded is encoded

0 commit comments

Comments
 (0)