Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: any Mapping assigned to a WritableDirectory is interpreted as a TTree or failure, no fall-through. #779

Merged
merged 1 commit into from Nov 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/uproot/writing/identify.py
Expand Up @@ -22,6 +22,7 @@
import numpy

import uproot.compression
import uproot.extras
import uproot.pyroot
import uproot.writing._cascadetree

Expand Down Expand Up @@ -88,24 +89,22 @@ def add_to_directory(obj, name, directory, streamers):
if isinstance(branch_array, Mapping) and all(
uproot._util.isstr(x) for x in branch_array
):
okay = True
datum = {}
metadatum = {}
for kk, vv in branch_array.items():
try:
vv = uproot._util.ensure_numpy(vv)
except TypeError:
okay = False
raise TypeError(
f"unrecognizable array type {type(branch_array)} associated with {branch_name!r}"
) from None
datum[kk] = vv
branch_dtype = vv.dtype
branch_shape = vv.shape[1:]
if branch_shape != ():
branch_dtype = numpy.dtype((branch_dtype, branch_shape))
metadatum[kk] = branch_dtype

if not okay:
break

data[branch_name] = datum
metadata[branch_name] = metadatum

Expand All @@ -118,14 +117,13 @@ def add_to_directory(obj, name, directory, streamers):
try:
branch_array = uproot._util.ensure_numpy(branch_array)
except TypeError:
try:
import awkward
except ImportError:
break
awkward = uproot.extras.awkward()
try:
branch_array = awkward.from_iter(branch_array)
except Exception:
break
raise TypeError(
f"unrecognizable array type {type(branch_array)} associated with {branch_name!r}"
) from None
else:
data[branch_name] = branch_array
metadata[branch_name] = awkward.type(branch_array)
Expand Down