Skip to content

Commit 0360984

Browse files
committed
clean up _prune_and_rename
1 parent f231fc3 commit 0360984

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/pyhf/workspace.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -583,40 +583,39 @@ def _prune_and_rename(
583583
),
584584
)
585585
for modifier in sample['modifiers']
586+
# we want to remove modifiers only if channel is not in list of channels to keep,
587+
# we want to remove modifiers only if sample is not in list of samples to keep
586588
if (
587-
channel['name'] not in prune_channels
588-
and prune_channels != []
589-
) # want to remove only if channel is in prune_channels or if prune_channels is empty, i.e. we want to prune this modifier for every channel
589+
prune_channels
590+
and channel['name'] not in prune_channels
591+
)
590592
or (
591-
sample['name'] not in prune_samples
592-
and prune_samples != []
593-
) # want to remove only if sample is in prune_samples or if prune_samples is empty, i.e. we want to prune this modifier for every sample
593+
prune_samples
594+
and sample['name'] not in prune_samples
595+
)
594596
or (
595597
modifier['name'] not in prune_modifiers
596598
and modifier['type'] not in prune_modifier_types
597599
)
600+
# need to keep the modifier in case it is used in another measurement
598601
or prune_measurements
599-
!= [] # need to keep the modifier in case it is used in another measurement
600602
],
601603
}
602604
for sample in channel['samples']
603-
if (
604-
channel['name'] not in prune_channels
605-
and prune_channels != []
606-
) # want to remove only if channel is in prune_channels or if prune_channels is empty, i.e. we want to prune this sample for every channel
605+
# we want to remove samples only if channel is not in list of channels to keep,
606+
# we want to remove samples only if no modifiers are to be pruned
607+
if (prune_channels and channel['name'] not in prune_channels)
607608
or sample['name'] not in prune_samples
608609
or prune_modifiers
609-
!= [] # we only want to remove this sample if we did not specify modifiers to prune
610-
or prune_modifier_types != []
610+
or prune_modifier_types
611611
],
612612
}
613613
for channel in self['channels']
614+
# we want to remove channels only if no samples or modifiers are to be pruned
614615
if channel['name'] not in prune_channels
615-
or ( # we only want to remove this channel if we did not specify any samples or modifiers to prune
616-
prune_samples != []
617-
or prune_modifiers != []
618-
or prune_modifier_types != []
619-
)
616+
or prune_samples
617+
or prune_modifiers
618+
or prune_modifier_types
620619
],
621620
'measurements': [
622621
{
@@ -634,9 +633,11 @@ def _prune_and_rename(
634633
for parameter in measurement['config'][
635634
'parameters'
636635
] # we only want to remove this parameter if measurement is in prune_measurements or if prune_measurements is empty
636+
# we want to remove parameters from a measurement only
637+
# if measurement is not in keep_measurements
637638
if (
638-
measurement['name'] not in prune_measurements
639-
and prune_measurements != []
639+
prune_measurements
640+
and measurement['name'] not in prune_measurements
640641
)
641642
or parameter['name'] not in prune_modifiers
642643
],
@@ -646,22 +647,21 @@ def _prune_and_rename(
646647
},
647648
}
648649
for measurement in self['measurements']
649-
if measurement['name'] not in prune_measurements
650-
or prune_modifiers
651-
!= [] # we only want to remove this measurement if we did not specify parameters to remove
650+
# we want to remove measurements only if no parameters are to be pruned
651+
if measurement['name'] not in prune_measurements or prune_modifiers
652652
],
653653
'observations': [
654654
dict(
655655
copy.deepcopy(observation),
656656
name=rename_channels.get(observation['name'], observation['name']),
657657
)
658658
for observation in self['observations']
659+
# we want to remove this channels only
660+
# if no samples or modifiers are to be pruned
659661
if observation['name'] not in prune_channels
660-
or ( # we only want to remove this channel if we did not specify any samples or modifiers to prune
661-
prune_samples != []
662-
or prune_modifiers != []
663-
or prune_modifier_types != []
664-
)
662+
or prune_samples
663+
or prune_modifiers
664+
or prune_modifier_types
665665
],
666666
'version': self['version'],
667667
}

0 commit comments

Comments
 (0)