From 6ae8a4a7eb901080cf88540de2cd4a4da8f85b60 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Wed, 3 Jun 2026 10:56:52 +0200 Subject: [PATCH] added has_data method --- stand/adb.py | 7 +++++++ stand/api.py | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stand/adb.py b/stand/adb.py index afdad38..a091df2 100644 --- a/stand/adb.py +++ b/stand/adb.py @@ -38,4 +38,11 @@ class ArcticLibrary: return df + def has_data(self, *args, **kwargs): + try: + return not self.lib.read(*args, columns=[], **kwargs).data.index.empty + except adb.exceptions.NoSuchVersionException: + return False + + diff --git a/stand/api.py b/stand/api.py index 2a073c2..0aa4a04 100644 --- a/stand/api.py +++ b/stand/api.py @@ -25,11 +25,7 @@ def append(beamline: Beamline, pgroup: PGroup, run: int, row: dict[str, Any]): index = pd.Timestamp(run) # adb supports update only for timeseries indexes index = pd.Index([index], name="run") - try: - run_exists = not lib.read(pgroup, date_range=index, columns=[]).data.index.empty - except adb.exceptions.NoSuchVersionException: - run_exists = False - + run_exists = lib.has_data(pgroup, date_range=index) if run_exists: raise HTTPException(HTTPStatus.CONFLICT, f"run {run} exists already in {beamline}/{pgroup}")