Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/uproot/interpretation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def cache_key(self):
String that uniquely specifies this interpretation, to use as part of
an array's cache key.
"""
raise AssertionError
raise NotImplementedError(f"{type(self).__name__} has no cache_key")

@property
def typename(self):
Expand All @@ -49,14 +49,14 @@ def typename(self):
This type might not exactly correspond to the type in C++, but it would
have equivalent meaning.
"""
raise AssertionError
raise NotImplementedError(f"{type(self).__name__} has no typename")

@property
def numpy_dtype(self):
"""
The ``numpy.dtype`` to use to put objects of this type in a NumPy array.
"""
raise AssertionError
raise NotImplementedError(f"{type(self).__name__} has no numpy_dtype")

@staticmethod
def _make_context(context, index_format, header, tobject_header, breadcrumbs):
Expand Down Expand Up @@ -99,7 +99,7 @@ def awkward_form(
The ``awkward.forms.Form`` to use to put objects of type type in an
Awkward Array.
"""
raise AssertionError
raise NotImplementedError(f"{type(self).__name__} has no awkward_form")

def basket_array(
self,
Expand Down Expand Up @@ -135,7 +135,7 @@ def basket_array(
Performs the first step of interpretation, from uncompressed ``TBasket``
data to a temporary array.
"""
raise AssertionError
raise NotImplementedError(f"{type(self).__name__} has no basket_array")

def final_array(
self,
Expand Down Expand Up @@ -171,7 +171,7 @@ def final_array(
temporary arrays, one for each ``TBasket``, to a trimmed, finalized,
grouped array, produced by the ``library``.
"""
raise AssertionError
raise NotImplementedError(f"{type(self).__name__} has no final_array")

def __eq__(self, other):
raise AssertionError
Expand Down
11 changes: 10 additions & 1 deletion src/uproot/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,8 +1783,17 @@ def _iter(
"""
filter_name = uproot._util.regularize_filter(filter_name)
filter_classname = uproot._util.regularize_filter(filter_classname)
keys = self._keys
if not cycle:
# without cycle numbers, a name stands for its highest cycle, as in
# self[name], so the cycles of each name are visited from the highest
order = {}
for key in keys:
order.setdefault(key.fName, len(order))
keys = sorted(keys, key=lambda key: (order[key.fName], -key.fCycle))

seen = set()
for key in self._keys:
for key in keys:
if (filter_name is no_filter or filter_name(key.fName)) and (
filter_classname is no_filter or filter_classname(key.fClassName)
):
Expand Down
3 changes: 2 additions & 1 deletion src/uproot/sink/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def tell(self) -> int:
"""
Calls the file or file-like object's ``tell`` method.
"""
self._ensure()
if self._closed or not self._file:
self._ensure()
return self._file.tell()

def flush(self) -> None:
Expand Down
34 changes: 31 additions & 3 deletions src/uproot/writing/_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ def __repr__(self):
def allocation(self):
return self.num_bytes

@property
def location(self):
return self._location

@location.setter
def location(self, value):
if self._location != value:
self._file_dirty = True
if self._big is False:
# read from a file; it might have to be big in its new location
self._big = None
self._location = value

@property
def uncompressed_bytes(self):
return self._uncompressed_bytes
Expand Down Expand Up @@ -921,6 +934,16 @@ def freesegments(self):
return self._freesegments

def update_streamers(self, sink, streamers, flush=True):
# check them all before adding any, so that a rejected batch changes nothing
streamers = list(streamers)
for streamer in streamers:
if not isinstance(
streamer, (uproot.streamers.Model_TStreamerInfo, RawStreamerInfo)
):
raise TypeError(
f"streamers must be TStreamerInfo or RawStreamerInfo, not {type(streamer).__name__}"
)

where = len(self._rawstreamers)

for streamer in streamers:
Expand All @@ -941,7 +964,7 @@ def update_streamers(self, sink, streamers, flush=True):
)
)

elif isinstance(streamer, RawStreamerInfo):
else:
self._rawstreamers.append(
streamer.copy_to(self._key.location + self.num_bytes)
)
Expand All @@ -950,17 +973,20 @@ def update_streamers(self, sink, streamers, flush=True):

if flush:
self.write(sink)
sink.set_file_length(self._freesegments.fileheader.end)
sink.flush()

def _reallocate(self, self_num_bytes):
original_start = self._key.location
original_stop = self._key.location + self._key.allocation + self._allocation

self._key.location = None # let it assume the key might be big
self._key.seek_location = None
requested_num_bytes = self._key.num_bytes + self_num_bytes

self._key.location = self._freesegments.allocate(requested_num_bytes)
self._key.seek_location = self._key.location
self._allocation = self_num_bytes
self._allocation = requested_num_bytes - self._key.num_bytes

self._freesegments.release(original_start, original_stop)

Expand Down Expand Up @@ -1265,7 +1291,9 @@ def write(self, sink):

for key in self._dirty_keys:
copied = key.copy_to(self._dirty_keys_start)
copied.location = self._dirty_keys_start
# not through the setter: the copy in this list of keys must have
# the same size as the key itself, which isn't moving
copied._location = self._dirty_keys_start
copied.write(sink)
self._dirty_keys_start += copied.num_bytes

Expand Down
Loading
Loading