Skip to content

Commit

Permalink
fix for certain CLI datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
zbilodea committed Jul 4, 2024
1 parent 1ca6704 commit 2269efa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
52 changes: 30 additions & 22 deletions src/hepconvert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,39 @@ def parquet_to_root(
"-db",
"--drop-branches",
default=None,
type=list or dict or str,
type=str,
required=False,
help="Specify branch names to remove from the ROOT file. Either a str, list of str (for multiple branches), or a dict with form {'tree': 'branches'} to remove branches from certain ttrees. Wildcarding accepted.",
)
@click.option(
"-kb", "--keep-branches", default=None, type=list or dict or str, required=False
"-kb", "--keep-branches", default=None, type=str, required=False
)
@click.option(
"-s",
"--step-size",
default="100 MB",
type=str,
help="If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size to include. The string must be a number followed by a memory unit, such as “100 MB”.",
)
@click.option(
"-dt",
"--drop-trees",
default=None,
type=list or str,
type=str,
required=False,
help="Specify tree names to remove from the ROOT file. Wildcarding accepted.",
)
@click.option(
"-kt",
"--keep-trees",
default=None,
type=list or str,
type=str,
required=False,
help="Specify tree names to keep in the ROOT file. All others will be removed. Wildcarding accepted.",
)
@click.option("--progress-bar", is_flag=True)
@click.option("--cut", default=None, type=str or list, required=False)
@click.option("--expressions", default=None, type=str or list, required=False)
@click.option("--cut", default=None, type=str, required=False)
@click.option("--expressions", default=None, type=str, required=False)
@click.option("--title", type=str, required=False, default="")
@click.option(
"--initial-basket-capacity",
Expand Down Expand Up @@ -151,7 +158,7 @@ def copy_root(
initial_basket_capacity=10,
resize_factor=10.0,
counter_name=lambda counted: "n" + counted,
step_size=100,
step_size="100 MB",
compression="LZ4",
compression_level=1,
):
Expand Down Expand Up @@ -270,41 +277,42 @@ def add(
help="When the TTree metadata needs to be rewritten, this specifies how many more TBasket slots to allocate as a multiplicative factor.",
)
@click.option(
"-s",
"--step-size",
default="100 MB",
type=int or str,
type=str,
help="If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size to include. The string must be a number followed by a memory unit, such as “100 MB”.",
)
@click.option(
"-db",
"--drop-branches",
default=None,
type=list or dict or str,
type=str,
required=False,
help="Specify branch names to remove from the ROOT file. Either a str, list of str (for multiple branches), or a dict with form {'tree': 'branches'} to remove branches from certain ttrees. Wildcarding accepted.",
)
@click.option(
"-kb", "--keep-branches", default=None, type=list or dict or str, required=False
"-kb", "--keep-branches", default=None, type=str, required=False
)
@click.option(
"-dt",
"--drop-trees",
default=None,
type=list or str,
type=str,
required=False,
help="Specify tree names to remove from the ROOT file. Wildcarding accepted.",
help="Specify tree name to remove from the ROOT file. Wildcarding accepted.",
)
@click.option(
"-kt",
"--keep-trees",
default=None,
type=list or str,
type=str,
required=False,
help="Specify tree names to keep in the ROOT file.. Wildcarding accepted.",
help="Specify tree name to keep in the ROOT file.. Wildcarding accepted.",
)
@click.option("--progress-bar", is_flag=True)
@click.option("--cut", default=None, type=str or list, required=False)
@click.option("--expressions", default=None, type=str or list, required=False)
@click.option("--cut", default=None, type=str, required=False)
@click.option("--expressions", default=None, type=str, required=False)
@click.option(
"-f",
"--force",
Expand Down Expand Up @@ -398,20 +406,20 @@ def merge_root(
"-db",
"--drop-branches",
default=None,
type=list or dict or str,
type=str,
required=False,
help="Specify branch names to remove from the ROOT file. Either a str, list of str (for multiple branches), or a dict with form {'tree': 'branches'} to remove branches from certain ttrees. Wildcarding accepted.",
)
@click.option(
"-kb",
"--keep-branches",
default=None,
type=list or dict or str,
type=str,
required=False,
help="Specify branch names to keep in the ROOT file. Either a str, list of str (for multiple branches), or a dict with form {'tree': 'branches'} to keep only certain branches in certain ttrees. Wildcarding accepted.",
)
@click.option("--cut", default=None, type=str or list, required=False)
@click.option("--expressions", default=None, type=str or list, required=False)
@click.option("--cut", default=None, type=str, required=False)
@click.option("--expressions", default=None, type=str, required=False)
@click.option(
"-f",
"--force",
Expand All @@ -422,7 +430,7 @@ def merge_root(
@click.option(
"-s",
"--step-size",
type=int or str,
type=str,
default="100 MB",
help="Specify batch size for reading ROOT file. If an integer, the maximum number of entries to include in each iteration step; if a string, the maximum memory size to include.",
)
Expand Down Expand Up @@ -561,7 +569,7 @@ def root_to_parquet(
cut=None,
expressions=None,
force=False,
step_size="100 MB",
step_size="100MB",
list_to32=False,
string_to32=True,
bytestring_to32=True,
Expand Down
2 changes: 1 addition & 1 deletion src/hepconvert/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def filter_branches(tree, keep_branches, drop_branches, count_branches):
for b in tree.branches
if b.name not in count_branches and b.name in keys
]
return [b.name for b in tree.branches]
return [b.name for b in tree.branches if b.name not in count_branches]


def check_tqdm():
Expand Down
7 changes: 7 additions & 0 deletions src/hepconvert/copy_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def copy_root(
),
)
first = (True,)


try: # is this legal?
step_size = int(step_size)
except ValueError:
step_size = step_size

try:
f = uproot.open(in_file)
except FileNotFoundError:
Expand Down
7 changes: 6 additions & 1 deletion src/hepconvert/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ def merge_root(
),
)
first = True


try: # is this legal?
step_size = int(step_size)
except ValueError:
step_size = step_size

if not isinstance(files, list) and not isinstance(files, tuple):
path = Path(files)
files = sorted(path.glob("**/*.root"))
Expand Down
7 changes: 6 additions & 1 deletion src/hepconvert/root_to_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ def root_to_parquet(
msg = "Must specify 1 tree to write, cannot write ", len(trees), "trees."
raise AttributeError(msg) from None
tree = trees[0]


try: # is this legal?
step_size = int(step_size)
except ValueError:
step_size = step_size

filter_b = _filter_branches(f[tree], keep_branches, drop_branches)
# if there's a counter, rid of that too...
ak.to_parquet_row_groups(
Expand Down

0 comments on commit 2269efa

Please sign in to comment.