Skip to content

Commit

Permalink
Merge pull request #71 from FAST-HEP/BK_issue_67-interp_jagged_arrays
Browse files Browse the repository at this point in the history
Fix interpretation of user-defined JaggedArrays
  • Loading branch information
benkrikler authored Sep 21, 2019
2 parents a1398a5 + 259a4eb commit fbe0da3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion fast_carpenter/tree_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import uproot
from uproot.interp.jagged import asjagged
from uproot.interp.numerical import asdtype
import copy
import awkward

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion fast_carpenter/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.13.3
current_version = 0.13.4
commit = True
tag = False

Expand Down
21 changes: 21 additions & 0 deletions tests/summary/test_binned_dataframe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd
import copy
import numpy as np
import pytest
import fast_carpenter.summary.binned_dataframe as bdf
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit fbe0da3

Please sign in to comment.