Skip to content

Commit

Permalink
Fix messages and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghanse committed Jan 29, 2025
1 parent ba632ef commit 1607193
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
14 changes: 3 additions & 11 deletions src/databricks/labs/dqx/col_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,8 @@ def is_valid_date(col_name: str, date_format: str = "yyyy-MM-dd") -> Column:
condition = F.to_date(column, date_format).isNull()
return make_condition(
condition,
F.concat_ws(
" ",
F.lit("Value"),
column,
F.lit(f"is not a valid date with format '{date_format}'")
),
f"{col_name}_is_not_valid_date"
F.concat_ws("", F.lit("Value '"), column, F.lit(f"' is not a valid date with format '{date_format}'")),
f"{col_name}_is_not_valid_date",
)


Expand All @@ -406,10 +401,7 @@ def is_valid_timestamp(col_name: str, timestamp_format: str = "yyyy-MM-dd HH:mm:
return make_condition(
condition,
F.concat_ws(
" ",
F.lit("Value"),
column,
F.lit(f"is not a valid timestamp with format '{timestamp_format}'")
"", F.lit("Value '"), column, F.lit(f"' is not a valid timestamp with format '{timestamp_format}'")
),
f"{col_name}_is_not_valid_timestamp",
)
9 changes: 5 additions & 4 deletions tests/integration/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
value_is_not_null_and_is_in_list,
is_not_null_and_not_empty_array,
is_valid_date,
is_valid_timestamp,
)

SCHEMA = "a: string, b: int"
Expand Down Expand Up @@ -536,10 +537,10 @@ def test_col_is_valid_timestamp(spark):
test_df = spark.createDataFrame(data, schema_array)

actual = test_df.select(
is_valid_date("a"),
is_valid_date("b", "MM/dd/yyyy HH:mm:ss"),
is_valid_date("c", "yyyy-MM-dd HH:mm:ss"),
is_valid_date("d"),
is_valid_timestamp("a"),
is_valid_timestamp("b", "MM/dd/yyyy HH:mm:ss"),
is_valid_timestamp("c", "yyyy-MM-dd HH:mm:ss"),
is_valid_timestamp("d"),
)

checked_schema = """
Expand Down

0 comments on commit 1607193

Please sign in to comment.