From 01bf6ff3d89b23eb3b34213576e263fdb31cadfb Mon Sep 17 00:00:00 2001 From: sfc-gh-jsummer Date: Tue, 22 Oct 2024 17:33:40 -0500 Subject: [PATCH] Remove 3.9 uncompatible or typehint with None --- app_utils/shared_utils.py | 12 ++++++------ environment.yml | 6 +++--- partner/cortex.py | 14 +++++++------- partner/dbt.py | 16 ++++++++-------- partner/looker.py | 4 ++-- partner/partner_utils.py | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app_utils/shared_utils.py b/app_utils/shared_utils.py index efc39a56..993714cf 100644 --- a/app_utils/shared_utils.py +++ b/app_utils/shared_utils.py @@ -7,7 +7,7 @@ from datetime import datetime from enum import Enum from io import StringIO -from typing import Any, Optional, List +from typing import Any, Optional, List, Union import pandas as pd import streamlit as st @@ -200,7 +200,7 @@ def get_available_stages(schema: str) -> List[str]: return fetch_stages_in_schema(get_snowflake_connection(), schema) -def stage_selector_container() -> None | List[str]: +def stage_selector_container() -> Optional[List[str]]: """ Common component that encapsulates db/schema/stage selection for the admin app. When a db/schema/stage is selected, it is saved to the session state for reading elsewhere. @@ -1247,23 +1247,23 @@ class AppMetadata: """ @property - def user(self) -> str | None: + def user(self) -> Optional[str]: return os.getenv("SNOWFLAKE_USER") @property - def stage(self) -> str | None: + def stage(self) -> Optional[str]: if stage_exists(): stage = st.session_state.snowflake_stage return f"{stage.stage_database}.{stage.stage_schema}.{stage.stage_name}" return None @property - def model(self) -> str | None: + def model(self) -> Optional[str]: if semantic_model_exists(): return st.session_state.semantic_model.name # type: ignore return None - def to_dict(self) -> dict[str, str | None]: + def to_dict(self) -> dict[str, Union[str,None]]: return { "User": self.user, "Stage": self.stage, diff --git a/environment.yml b/environment.yml index a67b7400..e7aca6ba 100644 --- a/environment.yml +++ b/environment.yml @@ -2,8 +2,8 @@ name: sf_env channels: - snowflake dependencies: -- python=3.10.* -- pandas=2.2.2 +- python=3.8.* +- pandas=2.0.3 - tqdm=4.66.5 - streamlit=1.35.0 - loguru=0.5.3 @@ -13,7 +13,7 @@ dependencies: - ruamel.yaml=0.17.21 - pyarrow=14.0.2 - sqlglot=25.10.0 -- numpy=1.26.4 +- numpy=1.24.3 - python-dotenv=0.21.0 - urllib3=2.2.2 - requests=2.32.3 diff --git a/partner/cortex.py b/partner/cortex.py index ee09bb26..e701391d 100644 --- a/partner/cortex.py +++ b/partner/cortex.py @@ -18,11 +18,11 @@ def __init__(self, data: dict[str, Any]): self.data: dict[str, Any] = data self.name: str = data["name"] - self.synonyms: None | list[str] = data.get("synonyms", None) + self.synonyms: Optional[list[str]] = data.get("synonyms", None) self.data_type: str = data.get("data_type", "TEXT") self.expr: str = data["expr"] - self.description: None | str = data.get("description", None) - self.sample_values: None | list[str] = data.get("sample_values", None) + self.description: Optional[str] = data.get("description", None) + self.sample_values: Optional[list[str]] = data.get("sample_values", None) self.unique: bool = data.get("unique", False) def get_name(self) -> str: @@ -90,13 +90,13 @@ class CortexSemanticTable: def __init__(self, data: dict[str, Any]): self.data: dict[str, Any] = data self.name: str = data["name"] - self.description: None | str = data["description"] + self.description: Optional[str] = data["description"] self.base_table_db: str = data["base_table"]["database"] self.base_table_schema: str = data["base_table"]["schema"] self.base_table_table: str = data["base_table"]["table"] - self.dimensions: None | list[dict[str, Any]] = data["dimensions"] - self.time_dimensions: None | list[dict[str, Any]] = data["time_dimensions"] - self.measures: None | list[dict[str, Any]] = data["measures"] + self.dimensions: Optional[list[dict[str, Any]]] = data["dimensions"] + self.time_dimensions: Optional[list[dict[str, Any]]] = data["time_dimensions"] + self.measures: Optional[list[dict[str, Any]]] = data["measures"] def get_data(self) -> dict[str, Any]: return self.data diff --git a/partner/dbt.py b/partner/dbt.py index 472e3053..a7a9f76d 100644 --- a/partner/dbt.py +++ b/partner/dbt.py @@ -1,4 +1,4 @@ -from typing import Any, Optional +from typing import Any, Optional, Union import pandas as pd import streamlit as st @@ -80,7 +80,7 @@ def upload_dbt_semantic() -> None: key="dbt_files", ) if uploaded_files: - partner_semantic: list[None | DBTSemanticModel] = [] + partner_semantic: list[Union[None,DBTSemanticModel]] = [] for file in uploaded_files: partner_semantic.extend(read_dbt_yaml(file)) # type: ignore @@ -111,7 +111,7 @@ def __init__(self, entity: dict[str, Any]): self.name: str = entity["name"] self.type: str = entity.get("type", None) self.expr: str = entity.get("expr", self.name) - self.description: None | str = entity.get("description", None) + self.description: Optional[str] = entity.get("description", None) self.cortex_map = { "name": self.name, "description": self.description, @@ -153,7 +153,7 @@ class DBTMeasure(DBTEntity): def __init__(self, entity: dict[str, Any]): super().__init__(entity) - self.agg: None | str = entity.get("agg", None) + self.agg: Optional[str] = entity.get("agg", None) self.cortex_map = { "name": self.name, "description": self.description, @@ -195,10 +195,10 @@ class DBTSemanticModel: def __init__(self, data: dict[str, Any]): self.data: dict[str, Any] = data self.name: str = data["name"] - self.description: None | str = data.get("description", None) - self.entities: None | list[dict[str, Any]] = data["entities"] - self.dimensions: None | list[dict[str, Any]] = data["dimensions"] - self.measures: None | list[dict[str, Any]] = data["measures"] + self.description: Optional[str] = data.get("description", None) + self.entities: Optional[list[dict[str, Any]]] = data["entities"] + self.dimensions: Optional[list[dict[str, Any]]] = data["dimensions"] + self.measures: Optional[list[dict[str, Any]]] = data["measures"] def get_data(self) -> dict[str, Any]: return self.data diff --git a/partner/looker.py b/partner/looker.py index fe874670..f728a0b7 100644 --- a/partner/looker.py +++ b/partner/looker.py @@ -1,5 +1,5 @@ import os -from typing import Any, Optional +from typing import Any, Optional, Union import pandas as pd import streamlit as st @@ -523,7 +523,7 @@ def render_looker_explore_as_table( target_lag: Optional[int] = 20, target_lag_unit: Optional[str] = "minutes", warehouse: Optional[str] = None, -) -> None | dict[str, dict[str, str]]: +) -> Union[None,dict[str, dict[str, str]]]: """ Creates materialized table corresponding to Looker Explore. Args: diff --git a/partner/partner_utils.py b/partner/partner_utils.py index 49aa7d43..afc858bf 100644 --- a/partner/partner_utils.py +++ b/partner/partner_utils.py @@ -113,7 +113,7 @@ def __init__(self, row_data: pd.Series) -> None: # type: ignore else {} ) - def render_row(self) -> None | dict[str, Any]: # type: ignore + def render_row(self) -> Union[None, dict[str, Any]]: # type: ignore toggle_options = ["merged", "cortex", "partner", "remove"] metadata = {}