You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
1.4 KiB

import pandas as pd
from util.setup_logging import get_logger
logger = get_logger(__name__)
from util.data_prepare import COL_DATE
def parse_timestamp(df, timestamp_format, col_timestamp=COL_DATE):
try:
df[col_timestamp] = pd.to_datetime(df[col_timestamp], format=timestamp_format)
return df
except:
try:
df[col_timestamp] = pd.to_datetime(df[col_timestamp], unit='s')
return df
except:
try:
df[col_timestamp] = pd.to_datetime(df[col_timestamp], infer_datetime_format=True)
logger.debug(f'Since the timestamp format is neither the ITSI format, nor the Unix epoch format, we infer the timestamp format (example: {df[col_timestamp].iloc[0]}).')
return df
except:
logger.warning(f'The timestamp format "{timestamp_format}" does not match the timestamp format of your data. \
Please ensure your data has a timestamp format supported by ITSI, or check that the timestamp format passed to the "timestamp_format" argument is correct.')
raise ValueError(f'The timestamp format "{timestamp_format}" does not match the timestamp format of your data. \
Please ensure your data has a timestamp format supported by ITSI, or check that the timestamp format passed to the "timestamp_format" argument is correct.')