From bded03c0f03d9c61f5e23d3813141eb28ed70e23 Mon Sep 17 00:00:00 2001 From: Sultan Iman <354868+sultaniman@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:28:44 +0200 Subject: [PATCH] Add yaml representer for pendulum datetime (#1192) * Add yaml representer for pendulum datetime * Fix linting issues --- .../streamlit_app/blocks/resource_state.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/dlt/helpers/streamlit_app/blocks/resource_state.py b/dlt/helpers/streamlit_app/blocks/resource_state.py index 8ea1256a1f..86b8effc98 100644 --- a/dlt/helpers/streamlit_app/blocks/resource_state.py +++ b/dlt/helpers/streamlit_app/blocks/resource_state.py @@ -1,12 +1,19 @@ +from typing import Union + import dlt +import pendulum import streamlit as st import yaml -from dlt.common import json -from dlt.common.libs.pandas import pandas as pd -from dlt.common.pipeline import resource_state, TSourceState -from dlt.common.schema.utils import group_tables_by_resource -from dlt.helpers.streamlit_app.widgets.tags import tag + +def date_to_iso( + dumper: yaml.SafeDumper, data: Union[pendulum.Date, pendulum.DateTime] +) -> yaml.ScalarNode: + return dumper.represent_datetime(data) # type: ignore[arg-type] + + +yaml.representer.SafeRepresenter.add_representer(pendulum.Date, date_to_iso) # type: ignore[arg-type] +yaml.representer.SafeRepresenter.add_representer(pendulum.DateTime, date_to_iso) # type: ignore[arg-type] def resource_state_info( @@ -21,6 +28,7 @@ def resource_state_info( return resource = schema["resources"].get(resource_name) + with st.expander("Resource state", expanded=(resource is None)): if not resource: st.info(f"{resource_name} is missing resource state")