Skip to content

Commit 9e168b5

Browse files
committed
Add test for None in time column
1 parent bec2a66 commit 9e168b5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test/test_scan_pandas.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,36 @@ def test_copy_from_timedelta_nat(conn_db_empty: ConnDB) -> None:
893893
assert row2[0] == 2
894894
assert row2[1] is None
895895
assert not result.has_next()
896+
897+
898+
def test_copy_from_datetime_none(conn_db_empty: ConnDB) -> None:
899+
"""Test that COPY FROM with None in a datetime column stores NULL.
900+
Pandas auto-infers the column as datetime64[ns] and converts None to NaT
901+
"""
902+
conn, _ = conn_db_empty
903+
conn.execute(
904+
"CREATE NODE TABLE Test (id INT64, ts TIMESTAMP, PRIMARY KEY (id))"
905+
)
906+
df = pd.DataFrame(
907+
{
908+
"id": [1, 2],
909+
"ts": [datetime.datetime(2024, 1, 15, 10, 30), None],
910+
}
911+
)
912+
# Sanity check: pandas should infer a nullable datetime64[ns] column
913+
assert df["ts"].dtype == "datetime64[ns]"
914+
915+
conn.execute(
916+
"COPY Test FROM (LOAD FROM $df RETURN "
917+
"CAST(`id` AS INT64) AS `id`, "
918+
"CAST(`ts` AS TIMESTAMP) AS `ts`)",
919+
{"df": df},
920+
)
921+
result = conn.execute("MATCH (t:Test) RETURN t.id, t.ts ORDER BY t.id")
922+
row1 = result.get_next()
923+
assert row1[0] == 1
924+
assert row1[1] == datetime.datetime(2024, 1, 15, 10, 30)
925+
row2 = result.get_next()
926+
assert row2[0] == 2
927+
assert row2[1] is None
928+
assert not result.has_next()

0 commit comments

Comments
 (0)