Skip to content

Commit 7b312aa

Browse files
add is_elapsed checker
1 parent 6cf26e4 commit 7b312aa

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

schimpy/model_time.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,26 @@ def elapsed_to_timestamp(input, time_basis, elapsed_unit="s"):
428428
return out_df
429429

430430

431-
def read_th(input, time_basis=None, to_timestamp=True, elapsed_unit="s"):
432-
"""Read input file and return dataframe.
433-
Automatically converts to timestamp if time_basis is supplied unless to_timestamp is False
431+
def is_elapsed(input):
432+
"""Check whether the input file is 'elapsed' or 'timestamped'.
433+
Uses the first line of the file to determine this.
434+
If there are any non-numeric characters then that's a timestamped file and is_elapsed would return False
434435
"""
435436

436-
# check if first line contains headers (and thus is elapsed)
437437
with open(input, "r") as f:
438438
first_line = f.readline().strip()
439439
is_elapsed = all(re.match(r"^[-+]?\d*\.?\d+$", s) for s in first_line.split())
440440

441-
if is_elapsed:
441+
return is_elapsed
442+
443+
444+
def read_th(input, time_basis=None, to_timestamp=True, elapsed_unit="s"):
445+
"""Read input file and return dataframe.
446+
Automatically converts to timestamp if time_basis is supplied unless to_timestamp is False
447+
"""
448+
449+
# check if first line contains headers (and thus is elapsed)s
450+
if is_elapsed(input):
442451
# read elapsed file
443452
if time_basis is None:
444453
raise ValueError(

0 commit comments

Comments
 (0)