From 43276a0ced69a495569284da8735d308dc518c94 Mon Sep 17 00:00:00 2001 From: Jonas 'Mayou36' Eschle <mayou36@jonas.eschle.com> Date: Mon, 2 Oct 2017 14:30:48 +0200 Subject: [PATCH 1/2] - test fail marked possible reason, bug fixed --- analysis/data/loaders.py | 2 +- tests/test_data.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/data/loaders.py b/analysis/data/loaders.py index 55968db..ca7baff 100644 --- a/analysis/data/loaders.py +++ b/analysis/data/loaders.py @@ -171,7 +171,7 @@ def get_root_from_pandas_file(file_name, tree_name, kwargs): # Variables var_list = kwargs.get('variables', None) # Raise an error if some weights are not loaded. - if not (set(weights_to_normalize+weights_not_to_normalize).issubset(set(var_list))) : + if var_list and not (set(weights_to_normalize+weights_not_to_normalize).issubset(set(var_list))) : raise ValueError("Missing weights in the list of variables read from input file.") acc_var = '' # Acceptance specified diff --git a/tests/test_data.py b/tests/test_data.py index 20b5b3e..3f4418c 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -46,7 +46,7 @@ def test_load_with_weights(pandas_weights): 'tree': 'ds', 'output-format': 'root', 'input-type': 'pandas', - 'weights': 'half'}) + 'weights': 'half'}) # wrong keyword? assert data.isWeighted() assert data.sumEntries() == 1000.0 # Correct normalization data.get(0) -- GitLab From 73d6052bd9eda10b28243eb586870cc90716c53f Mon Sep 17 00:00:00 2001 From: Albert Puig <albert.puig@cern.ch> Date: Sat, 2 Dec 2017 00:36:15 +0100 Subject: [PATCH 2/2] Fix tests. --- analysis/data/loaders.py | 2 +- tests/test_data.py | 20 +++----------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/analysis/data/loaders.py b/analysis/data/loaders.py index 08be7cb..32e428e 100644 --- a/analysis/data/loaders.py +++ b/analysis/data/loaders.py @@ -119,7 +119,7 @@ def _get_root_from_dataframe(frame, kwargs): # Variables var_list = list(frame.columns) # Raise an error if some weights are not loaded. - if var_list and not (set(weights_to_normalize+weights_not_to_normalize).issubset(set(var_list))): + if var_list and not set(weights_to_normalize+weights_not_to_normalize).issubset(set(var_list)): raise ValueError("Missing weights in the list of variables read from input file.") acc_var = '' # Acceptance specified diff --git a/tests/test_data.py b/tests/test_data.py index 88ba6bc..08ef32a 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -47,7 +47,7 @@ def test_load_with_weights(pandas_weights): 'tree': 'ds', 'output-format': 'root', 'input-type': 'pandas', - 'weights': 'half'}) # wrong keyword? + 'weights-to-normalize': 'half'}) assert data.isWeighted() assert data.sumEntries() == 1000.0 # Correct normalization data.get(0) @@ -58,32 +58,18 @@ def test_load_with_weights(pandas_weights): 'tree': 'ds', 'output-format': 'root', 'input-type': 'pandas', - 'weights': ['half', 'quarter'], - 'weight_var': 'weight'}) + 'weights-to-normalize': ['half', 'quarter']}) assert data.isWeighted() assert data.sumEntries() == 1000.0 # Correct normalization data.get(0) assert data.weight() == 1.0 # Since all weights are equal - # This should fail - try: - data = get_data({'name': 'Test', - 'source': file_name, - 'tree': 'ds', - 'output-format': 'root', - 'input-type': 'pandas', - 'weights': ['half', 'quarter']}) - except KeyError: - pass - else: - assert False # And now product of the three to make sure it's not chance data = get_data({'name': 'Test', 'source': file_name, 'tree': 'ds', 'output-format': 'root', 'input-type': 'pandas', - 'weights': ['half', 'quarter', 'asym'], - 'weight_var': 'weight'}) + 'weights-to-normalize': ['half', 'quarter', 'asym']}) if not data.isWeighted(): return False # Correct normalization -- GitLab