From 645d403cbd1f84187b918f0f34c83b35ad36ff89 Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sat, 21 Sep 2019 13:03:59 +0200 Subject: [PATCH 1/4] Correctly interpret user-defined variables for uproot --- fast_carpenter/tree_wrapper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fast_carpenter/tree_wrapper.py b/fast_carpenter/tree_wrapper.py index 56b1785..2b71028 100644 --- a/fast_carpenter/tree_wrapper.py +++ b/fast_carpenter/tree_wrapper.py @@ -7,6 +7,7 @@ """ import uproot from uproot.interp.jagged import asjagged +from uproot.interp.numerical import asdtype import copy import awkward @@ -19,7 +20,7 @@ def wrapped_interpret(branch, *args, **kwargs): if isinstance(branch, WrappedTree.FakeBranch): if isinstance(branch._values, awkward.JaggedArray): - return asjagged(branch._values.content) + return asjagged(asdtype(branch._values.content.dtype.fields)) else: return branch._values From 5feccf738dfe0957b08e616e89dc671a95b1c141 Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sat, 21 Sep 2019 13:15:31 +0200 Subject: [PATCH 2/4] Add unit test for issue #67 --- tests/summary/test_binned_dataframe.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/summary/test_binned_dataframe.py b/tests/summary/test_binned_dataframe.py index afc9240..b8b0c4f 100644 --- a/tests/summary/test_binned_dataframe.py +++ b/tests/summary/test_binned_dataframe.py @@ -1,4 +1,5 @@ import pandas as pd +import copy import numpy as np import pytest import fast_carpenter.summary.binned_dataframe as bdf @@ -150,6 +151,26 @@ def test_BinnedDataframe_numexpr(binned_df_3, tmpdir): assert len(binned_df_3._weights) == 1 +def test_BinnedDataframe_user_var_run(config_3, tmpdir, full_wrapped_tree): + config_4 = copy.deepcopy(config_3) + config_4["binning"][0]["in"] = "Electron_Pt" + binned_df_4 = bdf.BinnedDataframe("binned_df_4", out_dir="somewhere", **config_4) + + chunk = FakeBEEvent(full_wrapped_tree, "mc") + px, py = chunk.tree.arrays(["Electron_Px", "Electron_Py"], outputtype=tuple) + pt = np.hypot(px, py) + chunk.tree.new_variable("Electron_Pt", pt) + collector = binned_df_4.collector() + + binned_df_4.event(chunk) + dataset_readers_list = (("test_dataset", (binned_df_4,)),) + results = collector._prepare_output(dataset_readers_list) + + bin_centers = pd.IntervalIndex(results.index.get_level_values('electron_pT')).mid + mean = np.sum((bin_centers[1:-1] * results['n'][1:-1]) / results['n'][1:-1].sum()) + assert mean == pytest.approx(44.32584) + + def test_BinnedDataframe_numexpr_run_mc(binned_df_3, tmpdir, infile): chunk = FakeBEEvent(infile, "mc") collector = binned_df_3.collector() From 07da92adda3971754b3caf168cc6156660d2dd60 Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sat, 21 Sep 2019 13:20:45 +0200 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81bc563..c323baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed +## [0.13.4] - 2019-09-21 +### Changed +- Fixed interpretation of user-defined variables for uproot, issue #67, PR #71 [@benkrikler](https://github.com/benkrikler) + ## [0.13.3] - 2019-09-12 ### Changed - Add changes to support uproot 3.9.1 and greater, issue #68 [@benkrikler](https://github.com/benkrikler) From 259a4ebf552f51cd45377ed9fde94c1b07b6bcc1 Mon Sep 17 00:00:00 2001 From: Ben Krikler Date: Sat, 21 Sep 2019 13:20:51 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Bump=20version:=200.13.3=20=E2=86=92=200.13?= =?UTF-8?q?.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fast_carpenter/version.py | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fast_carpenter/version.py b/fast_carpenter/version.py index 0bb485f..19a05bb 100644 --- a/fast_carpenter/version.py +++ b/fast_carpenter/version.py @@ -12,5 +12,5 @@ def split_version(version): return tuple(result) -__version__ = '0.13.3' +__version__ = '0.13.4' version_info = split_version(__version__) # noqa diff --git a/setup.cfg b/setup.cfg index 14ebc4a..3d6e231 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.13.3 +current_version = 0.13.4 commit = True tag = False