Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 19, 2024
1 parent b3e4afa commit 07f6d46
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
46 changes: 23 additions & 23 deletions great_expectations/compatibility/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,76 @@
from great_expectations.compatibility.not_imported import NotImported

POSTGRESQL_NOT_IMPORTED = NotImported(
"postgresql connection components are not installed, please 'pip install psycopg2'" # noqa: E501
"postgresql connection components are not installed, please 'pip install psycopg2'"
)

try:
import psycopg2 # noqa: F401
import sqlalchemy.dialects.postgresql as postgresqltypes # noqa: TID251
import sqlalchemy.dialects.postgresql as postgresqltypes
except ImportError:
postgresqltypes = POSTGRESQL_NOT_IMPORTED # type: ignore[assignment]
postgresqltypes = POSTGRESQL_NOT_IMPORTED # type: ignore[assignment]

try:
from sqlalchemy.dialects.postgresql import TEXT
except (ImportError, AttributeError):
TEXT = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
TEXT = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import CHAR
except (ImportError, AttributeError):
CHAR = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
CHAR = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import INTEGER
except (ImportError, AttributeError):
INTEGER = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
INTEGER = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import SMALLINT
except (ImportError, AttributeError):
SMALLINT = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
SMALLINT = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import BIGINT
except (ImportError, AttributeError):
BIGINT = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
BIGINT = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import TIMESTAMP
except (ImportError, AttributeError):
TIMESTAMP = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
TIMESTAMP = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import DATE
except (ImportError, AttributeError):
DATE = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
DATE = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION
except (ImportError, AttributeError):
DOUBLE_PRECISION = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
DOUBLE_PRECISION = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import BOOLEAN
except (ImportError, AttributeError):
BOOLEAN = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
BOOLEAN = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]

try:
from sqlalchemy.dialects.postgresql import NUMERIC
except (ImportError, AttributeError):
NUMERIC = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]
NUMERIC = POSTGRESQL_NOT_IMPORTED # type: ignore[misc, assignment]


class POSTGRESQL_TYPES:
"""Namespace for PostgreSQL dialect types."""

TEXT=TEXT
CHAR=CHAR
INTEGER=INTEGER
SMALLINT=SMALLINT
BIGINT=BIGINT
TIMESTAMP=TIMESTAMP
DATE=DATE
DOUBLE_PRECISION=DOUBLE_PRECISION
BOOLEAN=BOOLEAN
NUMERIC=NUMERIC
TEXT = TEXT
CHAR = CHAR
INTEGER = INTEGER
SMALLINT = SMALLINT
BIGINT = BIGINT
TIMESTAMP = TIMESTAMP
DATE = DATE
DOUBLE_PRECISION = DOUBLE_PRECISION
BOOLEAN = BOOLEAN
NUMERIC = NUMERIC
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,11 @@ def _validate_pandas( # noqa: C901, PLR0912
def _validate_sqlalchemy(self, actual_column_type, expected_types_list, execution_engine):
if expected_types_list is None:
success = True
elif execution_engine.dialect_name in [GXSqlDialect.DATABRICKS, GXSqlDialect.POSTGRESQL, GXSqlDialect.SNOWFLAKE]:
elif execution_engine.dialect_name in [
GXSqlDialect.DATABRICKS,
GXSqlDialect.POSTGRESQL,
GXSqlDialect.SNOWFLAKE,
]:
success = isinstance(actual_column_type, str) and any(
actual_column_type.lower() == expected_type.lower()
for expected_type in expected_types_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ def _validate_sqlalchemy(self, actual_column_type, expected_type, execution_engi

if expected_type is None:
success = True
elif execution_engine.dialect_name in [GXSqlDialect.DATABRICKS, GXSqlDialect.POSTGRESQL, GXSqlDialect.SNOWFLAKE]:
elif execution_engine.dialect_name in [
GXSqlDialect.DATABRICKS,
GXSqlDialect.POSTGRESQL,
GXSqlDialect.SNOWFLAKE,
]:
success = (
isinstance(actual_column_type, str)
and actual_column_type.lower() == expected_type.lower()
Expand Down
14 changes: 9 additions & 5 deletions great_expectations/expectations/metrics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
overload,
)

import great_expectations.exceptions as gx_exceptions
import numpy as np
from dateutil.parser import parse
from packaging import version

import great_expectations.exceptions as gx_exceptions
from great_expectations.compatibility import aws, sqlalchemy, trino
from great_expectations.compatibility.sqlalchemy import (
sqlalchemy as sa,
Expand All @@ -38,7 +40,6 @@
GXSqlDialect,
)
from great_expectations.execution_engine.util import check_sql_engine_dialect
from packaging import version

try:
import psycopg2 # noqa: F401
Expand Down Expand Up @@ -75,9 +76,8 @@


if TYPE_CHECKING:
from typing_extensions import TypeAlias

import pandas as pd
from typing_extensions import TypeAlias

try:
import teradatasqlalchemy.dialect
Expand Down Expand Up @@ -414,7 +414,11 @@ def get_sqlalchemy_column_metadata( # noqa: C901
)

dialect_name = execution_engine.dialect.name
if dialect_name in [GXSqlDialect.DATABRICKS, GXSqlDialect.POSTGRESQL, GXSqlDialect.SNOWFLAKE]:
if dialect_name in [
GXSqlDialect.DATABRICKS,
GXSqlDialect.POSTGRESQL,
GXSqlDialect.SNOWFLAKE,
]:
# WARNING: Do not alter columns in place, as they are cached on the inspector
columns_copy = [column.copy() for column in columns]
for column in columns_copy:
Expand Down

0 comments on commit 07f6d46

Please sign in to comment.