Skip to content

Commit 19142ac

Browse files
committed
refactor timelog processing to handle dayfirst format in datetime conversion
1 parent 17212a9 commit 19142ac

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/biopsykit/io/io.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ def load_atimelogger_file(file_path: path_t, timezone: Optional[Union[datetime.t
293293
timelog.index.name = "phase"
294294
timelog.columns.name = "start_end"
295295

296-
timelog = timelog.apply(pd.to_datetime, axis=1).map(lambda val: val.tz_localize(timezone))
296+
probe_timelog = timelog.iloc[0, 0]
297+
dayfirst = "/" in probe_timelog
298+
timelog = timelog.apply(lambda ts, d=dayfirst: pd.to_datetime(ts, dayfirst=d), axis=1).map(
299+
lambda val: val.tz_localize(timezone)
300+
)
297301

298302
timelog = pd.DataFrame(timelog.T.unstack(), columns=["time"])
299303
timelog = timelog[::-1].reindex(["start", "end"], level="start_end")

0 commit comments

Comments
 (0)