Update instruments/readers/nasa_ames_reader.py to handle dirty text entries. Dirty entries of time variables that cannot be properly processed are sent to nat
This commit is contained in:
@ -152,10 +152,22 @@ def read_nasa_ames_as_dict(filename, instruments_dir: str = None, work_with_copy
|
|||||||
sep="\s+",
|
sep="\s+",
|
||||||
header=header_length - 1,
|
header=header_length - 1,
|
||||||
skip_blank_lines=True)
|
skip_blank_lines=True)
|
||||||
|
|
||||||
|
df['start_time'] = df['start_time'].astype(str).str.strip()
|
||||||
|
df['end_time'] = df['end_time'].astype(str).str.strip()
|
||||||
|
|
||||||
|
df['start_time'] = pd.to_numeric(df['start_time'], errors='coerce')
|
||||||
|
df['end_time'] = pd.to_numeric(df['end_time'], errors='coerce')
|
||||||
|
|
||||||
# Compute actual datetime from start_time and (if present) end_time
|
# Compute actual datetime from start_time and (if present) end_time
|
||||||
df['start_time'] = df['start_time'].apply(lambda x: start_date + timedelta(days=x))
|
df['start_time'] = df['start_time'].apply(
|
||||||
|
lambda x: start_date + timedelta(days=x) if pd.notna(x) else pd.NaT
|
||||||
|
)
|
||||||
|
|
||||||
if 'end_time' in df.columns:
|
if 'end_time' in df.columns:
|
||||||
df['end_time'] = df['end_time'].apply(lambda x: start_date + timedelta(days=x))
|
df['end_time'] = df['end_time'].apply(
|
||||||
|
lambda x: start_date + timedelta(days=x) if pd.notna(x) else pd.NaT
|
||||||
|
)
|
||||||
|
|
||||||
# Create header metadata dictionary
|
# Create header metadata dictionary
|
||||||
header_metadata_dict = {
|
header_metadata_dict = {
|
||||||
|
Reference in New Issue
Block a user