quantlab.utils.watermark.write_watermark#

quantlab.utils.watermark.write_watermark(path, through, labels=None)[source]#

Write a dated watermark reaching through to path atomically.

The file holds labels and through, indent=2 with sorted keys. It is written to a temporary file and renamed into place, so an interrupted write leaves the previous watermark.

Parameters:
pathstr or Path

The watermark file.

throughdate

The day the data is complete through.

labelsMapping[str, str] or None, default None

What the watermark is of (for example {"name": "prices"}).

Raises:
ValueError

If labels holds through.

Examples

>>> import tempfile
>>> from pathlib import Path
>>> path = Path(tempfile.mkdtemp()) / WATERMARK_FILE
>>> write_watermark(path, date(2024, 3, 14), {"name": "events", "field": "updated"})
>>> json.loads(path.read_text())
{'field': 'updated', 'name': 'events', 'through': '2024-03-14'}