Skip to content

Commit

Permalink
Merge pull request #38 from FAST-HEP/BK_fix_keep_specific_bins_expans…
Browse files Browse the repository at this point in the history
…ions

Fix keep specific bins expansions
  • Loading branch information
benkrikler authored Jun 19, 2020
2 parents e11d656 + f716ac8 commit b0065dd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.1] - 2020-06-19
### Fixed
- Allow multiple expansions for KeepSpecificBins in postproc, PR #38

## [0.8.0] - 2020-05-22
### Added
- Useability tweaks for plotting
Expand Down
6 changes: 5 additions & 1 deletion fast_plotter/postproc/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def keep_specific_bins(df, axis, keep, expansions={}):
expanded = [keys + (new, ) for keys, vals in expanded for new in vals]
expanded = [delim.join(vals) for vals in expanded]

expanded = [k.format(**{name: v}) for name, vals in expansions.items() for v in vals for k in expanded]
if expansions:
replacements = [dict()]
for name, vals in expansions.items():
replacements = [{name: v, **r} for v in vals for r in replacements]
expanded = [e.format(**r) for r in replacements for e in expanded]
out_df = keep_bins(out_df, delim.join(axis), expanded)
out_df = split_dimension(out_df, axis, delimeter=delim)
return out_df
Expand Down
2 changes: 1 addition & 1 deletion fast_plotter/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.8.0'
__version__ = '0.8.1'
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.8.0
current_version = 0.8.1
commit = True
tag = False

Expand Down
20 changes: 17 additions & 3 deletions tests/postproc/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,23 @@ def test_keep_bins(binned_df):
assert len(result) == 40


# def test_keep_specific_bins():
# #def keep_specific_bins(df, axis, keep, expansions={}):
# pass
def test_keep_specific_bins(binned_df):
keep = {"0": ["foo"], "1": ["bar"]}
result = funcs.keep_specific_bins(binned_df, axis=["int", "cat"], keep=keep)
assert len(result) == 10

result = funcs.keep_specific_bins(binned_df, axis=["int", "cat"], keep=keep, expansions=[])
assert len(result) == 10

expansions = dict(one=["bar"])
keep = {"0": ["foo"], "1": ["{one}"]}
result = funcs.keep_specific_bins(binned_df, axis=["int", "cat"], keep=keep, expansions=expansions)
assert len(result) == 10

expansions = dict(one=["bar"], two=["foo", "bar"])
keep = {"0": ["{two}"], "1": ["{one}"]}
result = funcs.keep_specific_bins(binned_df, axis=["int", "cat"], keep=keep, expansions=expansions)
assert len(result) == 15


def test_combine_cols_AND_split_dimension(binned_df):
Expand Down

0 comments on commit b0065dd

Please sign in to comment.