Skip to content

Commit

Permalink
Safeguard against version numbers in tree names
Browse files Browse the repository at this point in the history
* New version of uproot/awkward returns the version number for tree keys - but can't handle them in an `uproot.open`. Strip off the version number if it is there.
    * Classic example of VMS living on!
* Revise default configuration for backend name to reflect how ServiceX is usually configured, moving from `atlasxaod` to `atlasr21`.

Fixes #326
  • Loading branch information
gordonwatts authored Oct 22, 2023
1 parent c61bdad commit e9cd5a6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"AOD's",
"asyncio",
"atlasxaod",
"autopep",
"awks",
"AZNLOCTEQ",
"backend's",
Expand Down Expand Up @@ -50,6 +51,7 @@
"miniouser",
"mino",
"myfile",
"mypy",
"nargs",
"ncols",
"ndarray",
Expand All @@ -65,6 +67,10 @@
"protomolecule",
"ptetaphi",
"pyarrow",
"pycodestyle",
"pydocstyle",
"Pylance",
"pylint",
"pypa",
"pypi",
"pytest",
Expand Down Expand Up @@ -95,7 +101,8 @@
"unittests",
"URL's",
"xaod",
"xrootd"
"xrootd",
"yapf"
],
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestArgs": [
Expand Down
2 changes: 1 addition & 1 deletion servicex/config_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ default_return_data: parquet
backend_types:
- type: xaod
return_data: root-file
codegen: atlasxaod
codegen: atlasr21
- type: uproot
return_data: parquet
codegen: uproot
Expand Down
4 changes: 4 additions & 0 deletions servicex/data_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def do_the_work(file: Path) -> ak.Array:

with uproot.open(file) as f_in: # type: ignore
tree_name = f_in.keys()[0]
# If `tree_name` ends with a ";NN", (where NN is a number
# left over from VMS file versioning!), remove everything from the
# ';' on
tree_name = tree_name.split(";")[0]

if hasattr(uproot, "lazy"):
return uproot.lazy(f"{file}:{tree_name}") # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion servicex/servicex.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def __init__(
Arguments
dataset Name of a dataset from which queries will be selected.
backend_name The type of backend. Used only if we need to find an
backend_name The name of backend. Used only if we need to find an
end-point. If we do not have a `servicex_adaptor` then this
will default to xaod, unless you have any endpoint listed
in your servicex file. It will default to best match there,
Expand Down
4 changes: 3 additions & 1 deletion servicex/servicex_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_default_returned_datatype(
Args:
backend_name (Optional[str]): The backend type string (`xaod`, `uproot`, etc)
backend_name (Optional[str]): Override the backend type
Returns:
str: The backend datatype, like `root` or `parquet`.
Expand Down Expand Up @@ -171,6 +172,7 @@ def _get_backend_info(

# Now, extract the type and see if we can figure out any defaults from the
# `backend_types` info. Skip this if we have a type we are passed in.
override_backend_info = backend_type is not None
type_lookup = (
backend_type
if backend_type is not None
Expand All @@ -185,7 +187,7 @@ def _get_backend_info(
for bd in backend_defaults:
if bd["type"].as_str_expanded() == type_lookup:
for k in bd.keys():
if k not in config:
if override_backend_info or (k not in config):
config[k] = str(bd[k].as_str_expanded())

# Finally, a default return type
Expand Down
2 changes: 1 addition & 1 deletion tests/test_servicex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ async def test_codegen_default_by_backend(mocker, good_awkward_file_data):
await ds.get_data_rootfiles_async("(valid qastle string)")

called = mock_servicex_adaptor.query_json
assert called["codegen"] == "atlasxaod"
assert called["codegen"] == "atlasr21"


@pytest.mark.asyncio
Expand Down

0 comments on commit e9cd5a6

Please sign in to comment.