Skip to content

Commit

Permalink
mypy: fixup for fastavro 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
jvansanten committed Dec 21, 2023
1 parent 5060a5e commit 4b00aa3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ampel/ztf/dev/ZTFAlert.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ def _load_alert(cls, file_path: str) -> None | dict:
def _deserialize(f) -> None | dict:
""" """
reader = fastavro.reader(f)
return next(reader, None)
alert = next(reader, None)
if alert is None:
return alert
else:
assert isinstance(alert, dict)
return alert

1 change: 1 addition & 0 deletions ampel/ztf/t0/load/UWAlertLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def alerts(self, limit: None | int = None) -> Iterator[io.BytesIO]:
for message in itertools.islice(self._consumer, limit):
reader = fastavro.reader(io.BytesIO(message.value()))
alert = next(reader) # raise StopIteration
assert isinstance(alert, dict)
stats = topic_stats[message.topic()]
if alert["candidate"]["jd"] < stats[0]:
stats[0] = alert["candidate"]["jd"]
Expand Down
1 change: 1 addition & 0 deletions ampel/ztf/t0/load/ZTFAlertArchiverV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def emit() -> Iterator[bytes]:
if not alerts:
return
chunk = io.BytesIO()
assert schema is not None
fastavro.writer(chunk, schema, alerts)
yield chunk.getvalue()
alerts.clear()
Expand Down

0 comments on commit 4b00aa3

Please sign in to comment.