Skip to content

Commit 0eb4d41

Browse files
committed
Add date/datetime tests for a DuckDB table
1 parent 2384fde commit 0eb4d41

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

data_raw/x-02-duckdb.qmd

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ import polars as pl
99
import duckdb
1010
1111
tbl_xyz = pl.DataFrame({"x": [1, 2, 3, 4], "y": [4, 5, 6, 7], "z": [8, 8, 8, 8]})
12-
tbl_xyz_missing = pl.DataFrame(
13-
{"x": [1, 2, None, 4], "y": [4, None, 6, 7], "z": [8, None, 8, 8]}
14-
)
12+
tbl_xyz_missing = pl.DataFrame({"x": [1, 2, None, 4], "y": [4, None, 6, 7], "z": [8, None, 8, 8]})
1513
tbl_dates_times_text = pl.DataFrame(
1614
{
1715
"date": ["2021-01-01", "2021-02-01", None],
1816
"dttm": ["2021-01-01 00:00:00", None, "2021-02-01 00:00:00"],
1917
"text": [None, "5-egh-163", "8-kdg-938"],
2018
}
2119
)
20+
tbl_true_dates_times = pl.DataFrame(
21+
{
22+
"date_1": ["2021-01-01", "2021-02-01"],
23+
"date_2": ["2021-02-01", "2021-03-01"],
24+
"dttm_1": ["2021-01-01 02:30:00", "2021-02-01 02:30:00"],
25+
"dttm_2": ["2021-02-01 03:30:00", "2021-03-01 03:30:00"],
26+
}
27+
).with_columns(
28+
[
29+
pl.col("date_1").str.to_date(),
30+
pl.col("date_2").str.to_date(),
31+
pl.col("dttm_1").str.to_datetime(),
32+
pl.col("dttm_2").str.to_datetime(),
33+
]
34+
)
35+
2236
small_table = pb.load_dataset(dataset="small_table", tbl_type="polars")
2337
game_revenue = pb.load_dataset(dataset="game_revenue", tbl_type="polars")
2438
nycflights = pb.load_dataset(dataset="nycflights", tbl_type="polars")
@@ -47,6 +61,13 @@ with duckdb.connect(database="tbl_dates_times_text.ddb", read_only=False) as con
4761
""")
4862
```
4963

64+
```{python}
65+
with duckdb.connect(database="tbl_true_dates_times.ddb", read_only=False) as con:
66+
con.execute(f"""
67+
CREATE TABLE IF NOT EXISTS 'tbl_true_dates_times' AS SELECT * FROM tbl_true_dates_times;
68+
""")
69+
```
70+
5071
```{python}
5172
with duckdb.connect(database="small_table.ddb", read_only=False) as con:
5273
con.execute(f"""
524 KB
Binary file not shown.

tests/test_validate.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
TBL_TRUE_DATES_TIMES_LIST = [
8686
"tbl_true_dates_times_pd",
8787
"tbl_true_dates_times_pl",
88+
"tbl_true_dates_times_duckdb",
8889
]
8990

9091

@@ -199,6 +200,12 @@ def tbl_dates_times_text_duckdb():
199200
return ibis.connect(f"duckdb://{file_path}").table("tbl_dates_times_text")
200201

201202

203+
@pytest.fixture
204+
def tbl_true_dates_times_duckdb():
205+
file_path = pathlib.Path.cwd() / "tests" / "tbl_files" / "tbl_true_dates_times.ddb"
206+
return ibis.connect(f"duckdb://{file_path}").table("tbl_true_dates_times")
207+
208+
202209
@pytest.fixture
203210
def tbl_sqlite():
204211
file_path = pathlib.Path.cwd() / "tests" / "tbl_files" / "tbl_xyz.sqlite"
@@ -4105,13 +4112,6 @@ def test_col_schema_match_columns_only():
41054112

41064113
@pytest.mark.parametrize("tbl_fixture", TBL_TRUE_DATES_TIMES_LIST)
41074114
def test_date_validation_across_cols(request, tbl_fixture):
4108-
# {
4109-
# "date_1": pd.to_datetime(["2021-01-01", "2021-02-01"]),
4110-
# "date_2": pd.to_datetime(["2021-02-01", "2021-03-01"]),
4111-
# "dttm_1": pd.to_datetime(["2021-01-01 02:30:00", "2021-02-01 02:30:00"]),
4112-
# "dttm_2": pd.to_datetime(["2021-02-01 03:30:00", "2021-03-01 03:30:00"]),
4113-
# }
4114-
41154115
tbl = request.getfixturevalue(tbl_fixture)
41164116

41174117
assert (
@@ -4183,13 +4183,6 @@ def test_date_validation_across_cols(request, tbl_fixture):
41834183

41844184
@pytest.mark.parametrize("tbl_fixture", TBL_TRUE_DATES_TIMES_LIST)
41854185
def test_datetime_validation_across_cols(request, tbl_fixture):
4186-
# {
4187-
# "date_1": pd.to_datetime(["2021-01-01", "2021-02-01"]),
4188-
# "date_2": pd.to_datetime(["2021-02-01", "2021-03-01"]),
4189-
# "dttm_1": pd.to_datetime(["2021-01-01 02:30:00", "2021-02-01 02:30:00"]),
4190-
# "dttm_2": pd.to_datetime(["2021-02-01 03:30:00", "2021-03-01 03:30:00"]),
4191-
# }
4192-
41934186
tbl = request.getfixturevalue(tbl_fixture)
41944187

41954188
assert (

0 commit comments

Comments
 (0)