@@ -473,6 +473,9 @@ def _prune_and_rename(
473
473
Returns:
474
474
~pyhf.workspace.Workspace: A new workspace object with the specified components removed or renamed
475
475
476
+ Raises:
477
+ ~pyhf.exceptions.InvalidWorkspaceOperation: An item name to prune or rename does not exist in the workspace.
478
+
476
479
"""
477
480
# avoid mutable defaults
478
481
prune_modifiers = [] if prune_modifiers is None else prune_modifiers
@@ -487,6 +490,36 @@ def _prune_and_rename(
487
490
rename_channels = {} if rename_channels is None else rename_channels
488
491
rename_measurements = {} if rename_measurements is None else rename_measurements
489
492
493
+ for modifier_type in prune_modifier_types :
494
+ if modifier_type not in dict (self .modifiers ).values ():
495
+ raise exceptions .InvalidWorkspaceOperation (
496
+ f"{ modifier_type } is not one of the modifier types in this workspace."
497
+ )
498
+
499
+ for modifier_name in (* prune_modifiers , * rename_modifiers .keys ()):
500
+ if modifier_name not in dict (self .modifiers ):
501
+ raise exceptions .InvalidWorkspaceOperation (
502
+ f"{ modifier_name } is not one of the modifiers in this workspace."
503
+ )
504
+
505
+ for sample_name in (* prune_samples , * rename_samples .keys ()):
506
+ if sample_name not in self .samples :
507
+ raise exceptions .InvalidWorkspaceOperation (
508
+ f"{ sample_name } is not one of the samples in this workspace."
509
+ )
510
+
511
+ for channel_name in (* prune_channels , * rename_channels .keys ()):
512
+ if channel_name not in self .channels :
513
+ raise exceptions .InvalidWorkspaceOperation (
514
+ f"{ channel_name } is not one of the channels in this workspace."
515
+ )
516
+
517
+ for measurement_name in (* prune_measurements , * rename_measurements .keys ()):
518
+ if measurement_name not in self .measurement_names :
519
+ raise exceptions .InvalidWorkspaceOperation (
520
+ f"{ measurement_name } is not one of the measurements in this workspace."
521
+ )
522
+
490
523
newspec = {
491
524
'channels' : [
492
525
{
@@ -573,6 +606,9 @@ def prune(
573
606
Returns:
574
607
~pyhf.workspace.Workspace: A new workspace object with the specified components removed
575
608
609
+ Raises:
610
+ ~pyhf.exceptions.InvalidWorkspaceOperation: An item name to prune does not exist in the workspace.
611
+
576
612
"""
577
613
# avoid mutable defaults
578
614
modifiers = [] if modifiers is None else modifiers
@@ -605,6 +641,9 @@ def rename(self, modifiers=None, samples=None, channels=None, measurements=None)
605
641
Returns:
606
642
~pyhf.workspace.Workspace: A new workspace object with the specified components renamed
607
643
644
+ Raises:
645
+ ~pyhf.exceptions.InvalidWorkspaceOperation: An item name to rename does not exist in the workspace.
646
+
608
647
"""
609
648
# avoid mutable defaults
610
649
modifiers = {} if modifiers is None else modifiers
0 commit comments