From e7ce2593c84210dba535a744b1e4c454e61f9d99 Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <f.sauerburger@cern.ch> Date: Wed, 3 Jul 2019 16:20:02 +0200 Subject: [PATCH] Make cut names compatible with process labels Make cut names accessible via the 'label' attribute to allow for duck typing. --- nnfwtbn/cut.py | 10 +++++----- nnfwtbn/tests/test_cut.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nnfwtbn/cut.py b/nnfwtbn/cut.py index 22d0704..21fb501 100644 --- a/nnfwtbn/cut.py +++ b/nnfwtbn/cut.py @@ -58,16 +58,16 @@ class Cut: value 4 4 - Cuts might be named by passing the 'name' argument to the constructor. + Cuts might be named by passing the 'label' argument to the constructor. Cut names can be used during plotting as labels to specify the plotted region. - >>> sel_sr = Cut(lambda df: df.is_sr == 1, name="Signal Region") - >>> sel_sr.name + >>> sel_sr = Cut(lambda df: df.is_sr == 1, label="Signal Region") + >>> sel_sr.label 'Signal Region' """ - def __init__(self, func=None, name=None): + def __init__(self, func=None, label=None): """ Creates a new cut. The optional func argument is called with the dataframe upon evaluation. The function must return an index array. If @@ -75,7 +75,7 @@ class Cut: accepted by this cut. """ self.func = func - self.name = name + self.label = label def __call__(self, dataframe): """ diff --git a/nnfwtbn/tests/test_cut.py b/nnfwtbn/tests/test_cut.py index 3c8fbdb..f9759bc 100644 --- a/nnfwtbn/tests/test_cut.py +++ b/nnfwtbn/tests/test_cut.py @@ -253,11 +253,11 @@ class CutTestCase(unittest.TestCase): self.assertEqual(list(high_sale_years.sale), [4.7, 5.6, 7.5, 4.2]) self.assertEqual(list(high_sale_years.year), [2012, 2013, 2014, 2017]) - def test_name(self): + def test_label(self): """ Check that names specified during construction are available via the 'name' attribute. """ - high_sale = Cut(lambda df: df.sale > 4, name="High sales volume") - self.assertEqual(high_sale.name, "High sales volume") + high_sale = Cut(lambda df: df.sale > 4, label="High sales volume") + self.assertEqual(high_sale.label, "High sales volume") -- GitLab