From bf13083003ca498812fe7d540932d039bbbc17ed Mon Sep 17 00:00:00 2001 From: "Leaf, Andrew T" Date: Thu, 21 Sep 2023 09:43:23 -0500 Subject: [PATCH] fix(tdis.py::aggregate_dataframe_to_stress_period): cast start_datetime and end_datetime cols to datetime64[ns] so that pd.concat doesn't fail with heterogenous dtypes --- mfsetup/tdis.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mfsetup/tdis.py b/mfsetup/tdis.py index 2ce95dc4..81d7d7fd 100644 --- a/mfsetup/tdis.py +++ b/mfsetup/tdis.py @@ -708,7 +708,12 @@ def aggregate_dataframe_to_stress_period(data, id_column, data_column, datetime_ aggregated.reset_index(inplace=True) # add datetime back in - aggregated['start_datetime'] = pd.Timestamp(start) if start is not None else start_datetime + aggregated['start_datetime'] = start if start is not None else start_datetime + # enforce consistent datetime dtypes + # (otherwise pd.concat of multiple outputs from this function may fail) + for col in 'start_datetime', 'end_datetime': + if col in aggregated.columns: + aggregated[col] = aggregated[col].astype('datetime64[ns]') # drop original datetime column, which doesn't reflect dates for period averages drop_cols = [datetime_column]