Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Batch Expectations correctly handle date min and max values #10613

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
wip tests
  • Loading branch information
joshua-stauffer committed Nov 1, 2024
commit da3296ab3300cbb72d9d82d10bef83049913c28c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime, timezone

import pandas as pd
import sqlalchemy.dialects.postgresql as POSTGRESQL_TYPES
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't import directly from sqlalchemy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to non-Josh folks: the postgresql types were just imported from the sqla types, so they are equivalent. Which explains mypy being fine with this change.


Expand Down Expand Up @@ -27,6 +29,63 @@ def test_expect_column_min_to_be_between(batch_for_datasource) -> None:
assert result.success


@parameterize_batch_for_data_sources(
data_source_configs=[
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
PostgreSQLDatasourceTestConfig(column_types={"date": POSTGRESQL_TYPES.DATE}),
SnowflakeDatasourceTestConfig(column_types={"date": SNOWFLAKE_TYPES.TIMESTAMP_TZ}),
],
data=pd.DataFrame(
{
"date": [
str(datetime(year=2021, month=1, day=31, tzinfo=timezone.utc)),
str(datetime(year=2022, month=1, day=31, tzinfo=timezone.utc)),
str(datetime(year=2023, month=1, day=31, tzinfo=timezone.utc)),
]
}
),
)
def test_expect_column_min_to_be_between__dates(batch_for_datasource) -> None:
expectation = gxe.ExpectColumnMinToBeBetween(
column="date",
min_value=datetime(year=2021, month=1, day=1, tzinfo=timezone.utc),
max_value=datetime(year=2022, month=1, day=1, tzinfo=timezone.utc),
)
result = batch_for_datasource.validate(expectation)
assert result.success


@parameterize_batch_for_data_sources(
data_source_configs=[
PandasDataFrameDatasourceTestConfig(),
PandasFilesystemCsvDatasourceTestConfig(),
PostgreSQLDatasourceTestConfig(column_types={"date": POSTGRESQL_TYPES.TIMESTAMP}),
SnowflakeDatasourceTestConfig(column_types={"date": SNOWFLAKE_TYPES.TIMESTAMP_TZ}),
],
data=pd.DataFrame(
{
"date": [
# "2021-01-31",
# "2022-01-31",
# "2023-01-31",
str(datetime(year=2021, month=1, day=31, tzinfo=timezone.utc)),
str(datetime(year=2022, month=1, day=31, tzinfo=timezone.utc)),
str(datetime(year=2023, month=1, day=31, tzinfo=timezone.utc)),
]
}
),
)
def test_expect_column_max_to_be_between__dates(batch_for_datasource) -> None:
expectation = gxe.ExpectColumnMaxToBeBetween(
column="date",
min_value=datetime(year=2023, month=1, day=1, tzinfo=timezone.utc),
max_value=datetime(year=2024, month=1, day=1, tzinfo=timezone.utc),
)
result = batch_for_datasource.validate(expectation)
assert result.success


@parameterize_batch_for_data_sources(
data_source_configs=[
PandasDataFrameDatasourceTestConfig(),
Expand Down