Skip to content

Commit c3d013b

Browse files
committed
Remove old 'strict' cubelist extraction; add whatsnew.
1 parent f2a28bb commit c3d013b

File tree

3 files changed

+24
-39
lines changed

3 files changed

+24
-39
lines changed

docs/iris/src/whatsnew/contributions_3.0.0/docchange_2020-Apr-03_extract_clarification.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/iris/cube.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def xml(self, checksum=False, order=True, byteorder=True):
268268
# return our newly created XML string
269269
return doc.toprettyxml(indent=" ")
270270

271-
def extract(self, constraints, strict=False):
271+
def extract(self, constraints):
272272
"""
273273
Filter each of the cubes which can be filtered by the given
274274
constraints.
@@ -283,16 +283,9 @@ def extract(self, constraints, strict=False):
283283
* constraints (:class:`~iris.Constraint` or iterable of constraints):
284284
A single constraint or an iterable.
285285
286-
Keywords:
287-
288-
* strict (bool):
289-
If strict is True, then there must be exactly one cube which is
290-
filtered per constraint. Note: if a single constraint is given, a
291-
Cube is returned rather than a CubeList.
292-
293286
"""
294287
return self._extract_and_merge(
295-
self, constraints, strict, merge_unique=None
288+
self, constraints, strict=False, merge_unique=None
296289
)
297290

298291
def extract_cube(self, constraint):
@@ -385,13 +378,6 @@ def _extract_and_merge(
385378

386379
return result
387380

388-
def extract_strict(self, constraints):
389-
"""
390-
Calls :meth:`CubeList.extract` with the strict keyword set to True.
391-
392-
"""
393-
return self.extract(constraints, strict=True)
394-
395381
def extract_overlapping(self, coord_names):
396382
"""
397383
Returns a :class:`CubeList` of cubes extracted over regions

lib/iris/tests/test_constraints.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class TestCubeListStrictConstraint(StrictConstraintMixin, tests.IrisTest):
292292
suffix = "load_strict"
293293

294294
def load_match(self, files, constraints):
295-
cubes = iris.load(files).extract_strict(constraints)
295+
cubes = iris.load(files).extract_cubes(constraints)
296296
return cubes
297297

298298

@@ -317,25 +317,25 @@ def setUp(self):
317317

318318
def test_standard_name(self):
319319
constraint = iris.Constraint(self.standard_name)
320-
result = self.cubes.extract(constraint, strict=True)
320+
result = self.cubes.extract_cube(constraint)
321321
self.assertIsNotNone(result)
322322
self.assertEqual(result.standard_name, self.standard_name)
323323

324324
def test_long_name(self):
325325
constraint = iris.Constraint(self.long_name)
326-
result = self.cubes.extract(constraint, strict=True)
326+
result = self.cubes.extract_cube(constraint)
327327
self.assertIsNotNone(result)
328328
self.assertEqual(result.long_name, self.long_name)
329329

330330
def test_var_name(self):
331331
constraint = iris.Constraint(self.var_name)
332-
result = self.cubes.extract(constraint, strict=True)
332+
result = self.cubes.extract_cube(constraint)
333333
self.assertIsNotNone(result)
334334
self.assertEqual(result.var_name, self.var_name)
335335

336336
def test_stash(self):
337337
constraint = iris.Constraint(self.stash)
338-
result = self.cubes.extract(constraint, strict=True)
338+
result = self.cubes.extract_cube(constraint)
339339
self.assertIsNotNone(result)
340340
self.assertEqual(str(result.attributes["STASH"]), self.stash)
341341

@@ -348,7 +348,7 @@ def test_unknown(self):
348348
cube.attributes = None
349349
# Extract the unknown cube.
350350
constraint = iris.Constraint("unknown")
351-
result = self.cubes.extract(constraint, strict=True)
351+
result = self.cubes.extract_cube(constraint)
352352
self.assertIsNotNone(result)
353353
self.assertEqual(result.name(), "unknown")
354354

@@ -380,14 +380,14 @@ def test_standard_name(self):
380380

381381
# Match.
382382
constraint = NameConstraint(standard_name=self.standard_name)
383-
result = self.cubes.extract(constraint, strict=True)
383+
result = self.cubes.extract_cube(constraint)
384384
self.assertIsNotNone(result)
385385
self.assertEqual(result.standard_name, self.standard_name)
386386

387387
# Match - callable.
388388
kwargs = dict(standard_name=lambda item: item.startswith("air_pot"))
389389
constraint = NameConstraint(**kwargs)
390-
result = self.cubes.extract(constraint, strict=True)
390+
result = self.cubes.extract_cube(constraint)
391391
self.assertIsNotNone(result)
392392
self.assertEqual(result.standard_name, self.standard_name)
393393

@@ -397,7 +397,7 @@ def test_standard_name__None(self):
397397
constraint = NameConstraint(
398398
standard_name=None, long_name=self.long_name
399399
)
400-
result = self.cubes.extract(constraint, strict=True)
400+
result = self.cubes.extract_cube(constraint)
401401
self.assertIsNotNone(result)
402402
self.assertIsNone(result.standard_name)
403403
self.assertEqual(result.long_name, self.long_name)
@@ -410,7 +410,7 @@ def test_long_name(self):
410410

411411
# Match.
412412
constraint = NameConstraint(long_name=self.long_name)
413-
result = self.cubes.extract(constraint, strict=True)
413+
result = self.cubes.extract_cube(constraint)
414414
self.assertIsNotNone(result)
415415
self.assertEqual(result.long_name, self.long_name)
416416

@@ -420,7 +420,7 @@ def test_long_name(self):
420420
and item.startswith("air pot")
421421
)
422422
constraint = NameConstraint(**kwargs)
423-
result = self.cubes.extract(constraint, strict=True)
423+
result = self.cubes.extract_cube(constraint)
424424
self.assertIsNotNone(result)
425425
self.assertEqual(result.long_name, self.long_name)
426426

@@ -430,7 +430,7 @@ def test_long_name__None(self):
430430
constraint = NameConstraint(
431431
standard_name=self.standard_name, long_name=None
432432
)
433-
result = self.cubes.extract(constraint, strict=True)
433+
result = self.cubes.extract_cube(constraint)
434434
self.assertIsNotNone(result)
435435
self.assertEqual(result.standard_name, self.standard_name)
436436
self.assertIsNone(result.long_name)
@@ -443,14 +443,14 @@ def test_var_name(self):
443443

444444
# Match.
445445
constraint = NameConstraint(var_name=self.var_name)
446-
result = self.cubes.extract(constraint, strict=True)
446+
result = self.cubes.extract_cube(constraint)
447447
self.assertIsNotNone(result)
448448
self.assertEqual(result.var_name, self.var_name)
449449

450450
# Match - callable.
451451
kwargs = dict(var_name=lambda item: item.startswith("ap"))
452452
constraint = NameConstraint(**kwargs)
453-
result = self.cubes.extract(constraint, strict=True)
453+
result = self.cubes.extract_cube(constraint)
454454
self.assertIsNotNone(result)
455455
self.assertEqual(result.var_name, self.var_name)
456456

@@ -460,7 +460,7 @@ def test_var_name__None(self):
460460
constraint = NameConstraint(
461461
standard_name=self.standard_name, var_name=None
462462
)
463-
result = self.cubes.extract(constraint, strict=True)
463+
result = self.cubes.extract_cube(constraint)
464464
self.assertIsNotNone(result)
465465
self.assertEqual(result.standard_name, self.standard_name)
466466
self.assertIsNone(result.var_name)
@@ -473,14 +473,14 @@ def test_stash(self):
473473

474474
# Match.
475475
constraint = NameConstraint(STASH=self.stash)
476-
result = self.cubes.extract(constraint, strict=True)
476+
result = self.cubes.extract_cube(constraint)
477477
self.assertIsNotNone(result)
478478
self.assertEqual(str(result.attributes["STASH"]), self.stash)
479479

480480
# Match - callable.
481481
kwargs = dict(STASH=lambda stash: stash.item == 4)
482482
constraint = NameConstraint(**kwargs)
483-
result = self.cubes.extract(constraint, strict=True)
483+
result = self.cubes.extract_cube(constraint)
484484
self.assertIsNotNone(result)
485485

486486
def test_stash__None(self):
@@ -489,7 +489,7 @@ def test_stash__None(self):
489489
constraint = NameConstraint(
490490
standard_name=self.standard_name, STASH=None
491491
)
492-
result = self.cubes.extract(constraint, strict=True)
492+
result = self.cubes.extract_cube(constraint)
493493
self.assertIsNotNone(result)
494494
self.assertEqual(result.standard_name, self.standard_name)
495495
self.assertIsNone(result.attributes.get("STASH"))
@@ -499,7 +499,7 @@ def test_compound(self):
499499
constraint = NameConstraint(
500500
standard_name=self.standard_name, long_name=self.long_name
501501
)
502-
result = self.cubes.extract(constraint, strict=True)
502+
result = self.cubes.extract_cube(constraint)
503503
self.assertIsNotNone(result)
504504
self.assertEqual(result.standard_name, self.standard_name)
505505

@@ -518,7 +518,7 @@ def test_compound(self):
518518
long_name=self.long_name,
519519
var_name=self.var_name,
520520
)
521-
result = self.cubes.extract(constraint, strict=True)
521+
result = self.cubes.extract_cube(constraint)
522522
self.assertIsNotNone(result)
523523
self.assertEqual(result.standard_name, self.standard_name)
524524
self.assertEqual(result.long_name, self.long_name)
@@ -541,7 +541,7 @@ def test_compound(self):
541541
var_name=self.var_name,
542542
STASH=self.stash,
543543
)
544-
result = self.cubes.extract(constraint, strict=True)
544+
result = self.cubes.extract_cube(constraint)
545545
self.assertIsNotNone(result)
546546
self.assertEqual(result.standard_name, self.standard_name)
547547
self.assertEqual(result.long_name, self.long_name)
@@ -571,7 +571,7 @@ def test_unknown(self):
571571
cube.var_name = None
572572
cube.attributes = None
573573
constraint = NameConstraint(None, None, None, None)
574-
result = self.cubes.extract(constraint, strict=True)
574+
result = self.cubes.extract_cube(constraint)
575575
self.assertIsNotNone(result)
576576
self.assertIsNone(result.standard_name)
577577
self.assertIsNone(result.long_name)

0 commit comments

Comments
 (0)