diff --git a/stand/api.py b/stand/api.py index cfb2c35..afd00ea 100644 --- a/stand/api.py +++ b/stand/api.py @@ -13,19 +13,19 @@ router = APIRouter() @router.post("/tables/{pgroup}/append") def append(beamline: Beamline, pgroup: PGroup, run: int, row: dict[str, Any]): - timestamp = row.pop("timestamp", None) - timestamp = datetime.fromisoformat(timestamp) if timestamp else datetime.now() - row = {"timestamp": timestamp, **row} # setdefault would not force timestamp to be the first column + lib = adb.get(beamline) index = pd.Timestamp(run) # adb supports update only for timeseries indexes index = pd.Index([index], name="run") - lib = adb.get(beamline) - run_exists = not lib.read(pgroup, date_range=index, columns=[]).data.index.empty if run_exists: raise HTTPException(409, f"run {run} exists already in {beamline}/{pgroup}") + timestamp = row.pop("timestamp", None) + timestamp = datetime.fromisoformat(timestamp) if timestamp else datetime.now() + row = {"timestamp": timestamp, **row} # setdefault would not force timestamp to be the first column + df = pd.DataFrame(row, index=index) lib.append(pgroup, df)