Public Access
fix time_period latent crashes: treat missing time information as None
time_period is list[datetime] | None at runtime (None from old-format HDF5 files, [] from the constructor), but several sites subscripted it unguarded and crashed with TypeError/IndexError. - annotate time_period as list[datetime.datetime] | None - copy paths (get_accu_by_index, __iadd__ self-empty) use the guarded pattern already present in _copy_provenance - merges in __add__/__iadd__ only combine min/max when both sides carry time information; otherwise the result is None (provenance unknown) - write_to_tecmag raises ValueError when no time information is available instead of crashing while writing the header Clears all remaining time_period pyrefly errors (72 -> 63). Unit tests reproduce the crashes and pass with the fix. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
1 parent
27d05496ab
commit
804996cbd4
2 files changed
+120
-13
No files matched your search
@@ -70,7 +70,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
self.is_clipped = False
|
||||
|
||||
self.common_descriptions=None
|
||||
self.time_period=[]
|
||||
self.time_period: list[datetime.datetime] | None = []
|
||||
self.job_id = None # this does not make sense for an object accumulated from multiple job_ids
|
||||
self.job_ids = {}
|
||||
|
||||
@@ -139,7 +139,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
r.y_square.append(self.y_square[i][start:end+1].copy())
|
||||
if self.common_descriptions is not None:
|
||||
r.common_descriptions = self.common_descriptions.copy()
|
||||
r.time_period = self.time_period[:]
|
||||
r.time_period = self.time_period[:] if self.time_period is not None else None
|
||||
r.job_ids = self.job_ids.copy()
|
||||
r.is_clipped = self.is_clipped
|
||||
self.lock.release()
|
||||
@@ -369,6 +369,8 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
base_freq = [frequency, frequency, 0., 0.]
|
||||
offset_freq = [0., 0., 0., 0.]
|
||||
ob_freq = [sum(x) for x in zip(base_freq, offset_freq)]
|
||||
if self.time_period is None or len(self.time_period)==0:
|
||||
raise ValueError("write_to_tecmag: no time information available")
|
||||
date = self.time_period[0].strftime("%Y/%m/%d %H:%M:%S")
|
||||
|
||||
# data handling:
|
||||
@@ -679,7 +681,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
r = Accumulation(x = numpy.array(other.x, dtype="float32"), y = tmp_y, index = other.index, sampl_freq = other.sampling_rate, n = 1, error = False)
|
||||
if hasattr(other, "is_clipped"):
|
||||
r.is_clipped = other.is_clipped
|
||||
r.time_period=[other.job_date,other.job_date]
|
||||
r.time_period=[other.job_date,other.job_date] if other.job_date is not None else None
|
||||
r.job_id = other.job_id
|
||||
r.common_descriptions=other.description.copy()
|
||||
r.job_ids[other.job_id] = other.get_job_date()
|
||||
@@ -713,8 +715,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
else:
|
||||
r = Accumulation(x = numpy.array(self.x, dtype="float32"), y = tmp_y, n = self.n + 1, index = self.index, sampl_freq = self.sampling_rate, error = False)
|
||||
r.is_clipped = self.is_clipped or (hasattr(other, "is_clipped") and other.is_clipped)
|
||||
r.time_period=[min(self.time_period[0],other.job_date),
|
||||
max(self.time_period[1],other.job_date)]
|
||||
if self.time_period and other.job_date is not None:
|
||||
r.time_period=[min(self.time_period[0],other.job_date),
|
||||
max(self.time_period[1],other.job_date)]
|
||||
else:
|
||||
r.time_period=None
|
||||
r.job_id = other.job_id
|
||||
r.job_ids = self.job_ids.copy()
|
||||
r.job_ids[other.job_id] = other.get_job_date()
|
||||
@@ -785,8 +790,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
else:
|
||||
r = Accumulation(x = numpy.array(self.x, dtype="float32"), y = tmp_y, n = other.n + self.n, index = self.index, sampl_freq = self.sampling_rate, error = False)
|
||||
r.is_clipped = self.is_clipped or (hasattr(other, "is_clipped") and other.is_clipped)
|
||||
r.time_period=[min(self.time_period[0],other.time_period[0]),
|
||||
max(self.time_period[1],other.time_period[1])]
|
||||
if self.time_period and other.time_period:
|
||||
r.time_period=[min(self.time_period[0],other.time_period[0]),
|
||||
max(self.time_period[1],other.time_period[1])]
|
||||
else:
|
||||
r.time_period=None
|
||||
r.job_id = other.job_id
|
||||
r.job_ids = self.job_ids.copy()
|
||||
for i in other.job_ids:
|
||||
@@ -997,7 +1005,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
|
||||
if hasattr(other, "is_clipped"):
|
||||
self.is_clipped = other.is_clipped
|
||||
self.time_period=[other.job_date,other.job_date]
|
||||
self.time_period=[other.job_date,other.job_date] if other.job_date is not None else None
|
||||
self.job_id = other.job_id # added by Oleg Petrov
|
||||
self.job_ids[other.job_id] = other.get_job_date()
|
||||
self.common_descriptions=other.description.copy()
|
||||
@@ -1027,8 +1035,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
self.n += 1
|
||||
if hasattr(other, "is_clipped"):
|
||||
self.is_clipped = self.is_clipped or other.is_clipped
|
||||
self.time_period=[min(self.time_period[0],other.job_date),
|
||||
max(self.time_period[1],other.job_date)]
|
||||
if self.time_period and other.job_date is not None:
|
||||
self.time_period=[min(self.time_period[0],other.job_date),
|
||||
max(self.time_period[1],other.job_date)]
|
||||
else:
|
||||
self.time_period=None
|
||||
|
||||
self.job_id = other.job_id
|
||||
|
||||
@@ -1068,7 +1079,7 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
if hasattr(other, "is_clipped"):
|
||||
self.is_clipped = other.is_clipped
|
||||
self.common_descriptions=other.common_descriptions.copy()
|
||||
self.time_period=other.time_period[:]
|
||||
self.time_period=other.time_period[:] if other.time_period is not None else None
|
||||
self.job_id = other.job_id # added by Oleg Petrov
|
||||
self.job_ids.update(other.job_ids)
|
||||
self.lock.release()
|
||||
@@ -1099,8 +1110,11 @@ class Accumulation(Errorable, Drawable, DamarisFFT, Signalpath):
|
||||
self.n += other.n
|
||||
if hasattr(other, "is_clipped"):
|
||||
self.is_clipped = self.is_clipped or other.is_clipped
|
||||
self.time_period=[min(self.time_period[0],other.time_period[0]),
|
||||
max(self.time_period[1],other.time_period[1])]
|
||||
if self.time_period and other.time_period:
|
||||
self.time_period=[min(self.time_period[0],other.time_period[0]),
|
||||
max(self.time_period[1],other.time_period[1])]
|
||||
else:
|
||||
self.time_period=None
|
||||
self.job_id = other.job_id
|
||||
self.job_ids.update(other.job_ids)
|
||||
# Removes mismatched common description keys
|
||||
|
||||
Reference in new issue
Block a user