diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a4d7c73..6b722ebb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and the versioning aims to respect [Semantic Versioning](http://semver.org/spec/ ### Changed - Replace Marktrollen with MarktakteureUndRollen [#722](https://github.com/OpenEnergyPlatform/open-MaStR/pull/722) +- Zero fill specific date strings [#728](https://github.com/OpenEnergyPlatform/open-MaStR/pull/728) ### Removed diff --git a/open_mastr/xml_download/utils_write_to_database.py b/open_mastr/xml_download/utils_write_to_database.py index e71abc18..3cff7a43 100644 --- a/open_mastr/xml_download/utils_write_to_database.py +++ b/open_mastr/xml_download/utils_write_to_database.py @@ -280,9 +280,11 @@ def cast_date_columns_to_string(xml_table_name: str, df: pd.DataFrame) -> pd.Dat df[column_name] = pd.to_datetime(df[column_name], errors="coerce") if type(column[1].type) is Date: - df[column_name] = ( - df[column_name].dt.strftime("%Y-%m-%d").replace("NaT", None) - ) + mask = df[column_name].notna() + df[column_name] = df[column_name].dt.strftime("%Y-%m-%d") + df.loc[mask, column_name] = df.loc[mask, column_name].str.zfill(10) + df[column_name] = df[column_name].replace("NaT", None) + elif type(column[1].type) is DateTime: df[column_name] = ( df[column_name].dt.strftime("%Y-%m-%d %H:%M:%S.%f").replace("NaT", None)