From ef8111cf61a473873d0d419251dbbdf737cfc99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Kr=C3=A4mer?= Date: Thu, 26 Mar 2026 17:10:15 +0100 Subject: [PATCH 1/3] Zero fill specific date strings #719 --- open_mastr/xml_download/utils_write_to_database.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/open_mastr/xml_download/utils_write_to_database.py b/open_mastr/xml_download/utils_write_to_database.py index e71abc18..bf95ab8e 100644 --- a/open_mastr/xml_download/utils_write_to_database.py +++ b/open_mastr/xml_download/utils_write_to_database.py @@ -281,7 +281,10 @@ def cast_date_columns_to_string(xml_table_name: str, df: pd.DataFrame) -> pd.Dat if type(column[1].type) is Date: df[column_name] = ( - df[column_name].dt.strftime("%Y-%m-%d").replace("NaT", None) + df[column_name] + .dt.strftime("%Y-%m-%d") + .replace("NaT", None) + .str.zfill(10) ) elif type(column[1].type) is DateTime: df[column_name] = ( From 71078307abc7c9a72c9a792250bef8b696307b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Kr=C3=A4mer?= Date: Mon, 30 Mar 2026 14:29:11 +0100 Subject: [PATCH 2/3] Add change to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From d14829447bbecb87d63d5a347386c9f717e52cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Kr=C3=A4mer?= Date: Mon, 30 Mar 2026 14:44:22 +0100 Subject: [PATCH 3/3] Fix: only pad strings with zeros and skip None --- open_mastr/xml_download/utils_write_to_database.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/open_mastr/xml_download/utils_write_to_database.py b/open_mastr/xml_download/utils_write_to_database.py index bf95ab8e..3cff7a43 100644 --- a/open_mastr/xml_download/utils_write_to_database.py +++ b/open_mastr/xml_download/utils_write_to_database.py @@ -280,12 +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) - .str.zfill(10) - ) + 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)