Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion src_cpp/py_query_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ py::object PyQueryResult::convertValueToPyObject(const Value& value) {
}
case LogicalTypeID::INTERVAL: {
auto intervalVal = value.getValue<interval_t>();
auto days = Interval::DAYS_PER_MONTH * intervalVal.months + intervalVal.days;
auto years = intervalVal.months / Interval::MONTHS_PER_YEAR;
auto months = intervalVal.months % Interval::MONTHS_PER_YEAR;
auto days = years * Interval::DAYS_PER_YEAR + months * Interval::DAYS_PER_MONTH +
intervalVal.days;

return py::cast<py::object>(importCache->datetime.timedelta()(py::arg("days") = days,
py::arg("microseconds") = intervalVal.micros));
Expand Down
16 changes: 12 additions & 4 deletions src_py/_lbug_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,11 @@ def _convert_value(self, value: _LbugValue) -> Any:
),
"Failed to read interval",
)
total_days = int(out.days) + int(out.months) * 30
total_days = (
int(out.days)
+ (int(out.months) // 12) * 365
+ (int(out.months) % 12) * 30
)
return dt.timedelta(days=total_days, microseconds=int(out.micros))
if type_id in (_LBUG_LIST, _LBUG_ARRAY):
size = ctypes.c_uint64(0)
Expand Down Expand Up @@ -1937,7 +1941,8 @@ def _convert_value(self, value: _LbugValue) -> Any:
):
total_days = (
int(interval_probe.days)
+ int(interval_probe.months) * 30
+ (int(interval_probe.months) // 12) * 365
+ (int(interval_probe.months) % 12) * 30
)
out_obj[key] = dt.timedelta(
days=total_days,
Expand Down Expand Up @@ -2042,7 +2047,8 @@ def _convert_value(self, value: _LbugValue) -> Any:
):
total_days = (
int(interval_probe.days)
+ int(interval_probe.months) * 30
+ (int(interval_probe.months) // 12) * 365
+ (int(interval_probe.months) % 12) * 30
)
out_obj[key] = dt.timedelta(
days=total_days,
Expand Down Expand Up @@ -2095,7 +2101,9 @@ def _convert_value(self, value: _LbugValue) -> Any:
== _LBUG_SUCCESS
):
total_days = (
int(interval_probe.days) + int(interval_probe.months) * 30
int(interval_probe.days)
+ (int(interval_probe.months) // 12) * 365
+ (int(interval_probe.months) % 12) * 30
)
return dt.timedelta(
days=total_days, microseconds=int(interval_probe.micros)
Expand Down
20 changes: 10 additions & 10 deletions test/ground_truth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"eyeSight": 5.0,
"birthdate": date(1900, 1, 1),
"registerTime": datetime(2011, 8, 20, 11, 25, 30),
"lastJobDuration": timedelta(days=1082, seconds=46920),
"lastJobDuration": timedelta(days=1097, seconds=46920),
"workedHours": [10, 5],
"usedNames": ["Aida"],
"courseScoresPerTerm": [[10, 8], [6, 7, 8]],
Expand All @@ -34,7 +34,7 @@
"eyeSight": 5.1,
"birthdate": date(1900, 1, 1),
"registerTime": datetime(2008, 11, 3, 15, 25, 30, 526),
"lastJobDuration": timedelta(days=3750, seconds=46800, microseconds=24),
"lastJobDuration": timedelta(days=3800, seconds=46800, microseconds=24),
"workedHours": [12, 8],
"usedNames": ["Bobby"],
"courseScoresPerTerm": [[8, 9], [9, 10]],
Expand Down Expand Up @@ -74,7 +74,7 @@
"eyeSight": 4.8,
"birthdate": date(1950, 7, 23),
"registerTime": datetime(2031, 11, 30, 12, 25, 30),
"lastJobDuration": timedelta(days=3750, seconds=46800, microseconds=24),
"lastJobDuration": timedelta(days=3800, seconds=46800, microseconds=24),
"workedHours": [1, 9],
"usedNames": ["Wolfeschlegelstein", "Daniel"],
"courseScoresPerTerm": [[7, 4], [8, 8], [9]],
Expand Down Expand Up @@ -134,7 +134,7 @@
"eyeSight": 4.9,
"birthdate": date(1980, 10, 26),
"registerTime": datetime(1976, 12, 23, 4, 41, 42),
"lastJobDuration": timedelta(days=3750, seconds=46800, microseconds=24),
"lastJobDuration": timedelta(days=3800, seconds=46800, microseconds=24),
"workedHours": [1],
"usedNames": ["Grad"],
"courseScoresPerTerm": [[10]],
Expand All @@ -154,7 +154,7 @@
"eyeSight": 4.9,
"birthdate": date(1990, 11, 27),
"registerTime": datetime(2023, 2, 21, 13, 25, 30),
"lastJobDuration": timedelta(days=1082, seconds=46920),
"lastJobDuration": timedelta(days=1097, seconds=46920),
"workedHours": [10, 11, 12, 3, 4, 5, 6, 7],
"usedNames": ["Ad", "De", "Hi", "Kye", "Orlan"],
"courseScoresPerTerm": [[7], [10], [6, 7]],
Expand Down Expand Up @@ -192,7 +192,7 @@
"mark": 4.1,
"score": -100,
"history": "2 years 4 days 10 hours",
"licenseValidInterval": timedelta(days=9414),
"licenseValidInterval": timedelta(days=9544),
"rating": 0.78,
"state": {
"revenue": 152,
Expand Down Expand Up @@ -235,7 +235,7 @@
(0, 2): {
"date": date(2021, 6, 30),
"meetTime": datetime(1986, 10, 21, 21, 8, 31, 521000),
"validInterval": timedelta(days=3750, seconds=46800, microseconds=24),
"validInterval": timedelta(days=3800, seconds=46800, microseconds=24),
"comments": ["rnme", "m8sihsdnf2990nfiwf"],
"summary": {
"locations": ["'toronto'", "'waterloo'"],
Expand All @@ -247,7 +247,7 @@
(0, 3): {
"date": date(2021, 6, 30),
"meetTime": datetime(1946, 8, 25, 19, 7, 22),
"validInterval": timedelta(days=7232),
"validInterval": timedelta(days=7332),
"comments": ["njnojppo9u0jkmf", "fjiojioh9h9h89hph"],
"summary": {"locations": None, "transfer": None},
"notes": date(2020, 10, 10),
Expand All @@ -268,7 +268,7 @@
(2, 0): {
"date": date(2021, 6, 30),
"meetTime": datetime(1946, 8, 25, 19, 7, 22),
"validInterval": timedelta(days=3750, seconds=46800, microseconds=24),
"validInterval": timedelta(days=3800, seconds=46800, microseconds=24),
"comments": ["2huh9y89fsfw23", "23nsihufhw723"],
"summary": {
"locations": ["'paris'"],
Expand All @@ -292,7 +292,7 @@
(2, 5): {
"date": date(1950, 5, 14),
"meetTime": datetime(2012, 12, 11, 20, 7, 22),
"validInterval": timedelta(days=7232),
"validInterval": timedelta(days=7332),
"comments": ["fwh9y81232uisuiehuf", "ewnuihxy8dyf232"],
"summary": {
"locations": ["'vancouver'"],
Expand Down
10 changes: 5 additions & 5 deletions test/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ def _test_person_table(
col_name="a.lastJobDuration",
return_type=return_type,
expected_values=[
timedelta(days=1082, seconds=46920),
timedelta(days=3750, seconds=46800, microseconds=24),
timedelta(days=1097, seconds=46920),
timedelta(days=3800, seconds=46800, microseconds=24),
timedelta(days=2, seconds=1451),
timedelta(days=3750, seconds=46800, microseconds=24),
timedelta(days=3800, seconds=46800, microseconds=24),
timedelta(days=2, seconds=1451),
timedelta(seconds=1080, microseconds=24000),
timedelta(days=3750, seconds=46800, microseconds=24),
timedelta(days=1082, seconds=46920),
timedelta(days=3800, seconds=46800, microseconds=24),
timedelta(days=1097, seconds=46920),
],
)

Expand Down
4 changes: 2 additions & 2 deletions test/test_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_interval(conn_db_readonly: ConnDB) -> None:
conn, _ = conn_db_readonly
result = conn.execute("MATCH (a:person) WHERE a.ID = 0 RETURN a.lastJobDuration;")
assert result.has_next()
assert result.get_next() == [datetime.timedelta(days=1082, seconds=46920)]
assert result.get_next() == [datetime.timedelta(days=1097, seconds=46920)]
assert not result.has_next()
result.close()

Expand Down Expand Up @@ -298,7 +298,7 @@ def test_node(conn_db_readonly: ConnDB) -> None:
assert n["eyeSight"] == pytest.approx(5.0)
assert n["birthdate"] == datetime.date(1900, 1, 1)
assert n["registerTime"] == datetime.datetime(2011, 8, 20, 11, 25, 30)
assert n["lastJobDuration"] == datetime.timedelta(days=1082, seconds=46920)
assert n["lastJobDuration"] == datetime.timedelta(days=1097, seconds=46920)
assert n["courseScoresPerTerm"] == [[10, 8], [6, 7, 8]]
assert n["usedNames"] == ["Aida"]
assert not result.has_next()
Expand Down
30 changes: 15 additions & 15 deletions test/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ def _test_person_to_df(conn: lb.Connection) -> None:
]
assert str(pd["p.registerTime"].dtype) == "datetime64[us]"
assert pd["p.lastJobDuration"].tolist() == [
Timedelta("1082 days 13:02:00"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("0 days 00:18:00.024000"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1082 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
]
assert str(pd["p.lastJobDuration"].dtype) == "timedelta64[ns]"
assert pd["p.workedHours"].tolist() == [
Expand Down Expand Up @@ -319,14 +319,14 @@ def test_df_get_node(conn_db_readonly: ConnDB) -> None:
Timestamp("2023-02-21 13:25:30"),
],
"lastJobDuration": [
Timedelta("1082 days 13:02:00"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("0 days 00:18:00.024000"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1082 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
],
"workedHours": [
[10, 5],
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_df_get_node_rel(conn_db_readonly: ConnDB) -> None:
],
"lastJobDuration": [
Timedelta("48 hours 24 minutes 11 seconds"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
],
"workedHours": [[4, 5], [1, 9], [2]],
Expand All @@ -431,7 +431,7 @@ def test_df_get_node_rel(conn_db_readonly: ConnDB) -> None:
"2 years 4 hours 22 us 34 minutes",
],
"licenseValidInterval": [
Timedelta(days=9414),
Timedelta(days=9544),
Timedelta(days=3, seconds=36000, microseconds=100000),
Timedelta(days=3, seconds=36000, microseconds=100000),
],
Expand Down Expand Up @@ -476,7 +476,7 @@ def test_df_get_recursive_join(conn_db_readonly: ConnDB) -> None:
"isStudent": True,
"isWorker": False,
"lastJobDuration": datetime.timedelta(
days=3750, seconds=46800, microseconds=24
days=3800, seconds=46800, microseconds=24
),
"registerTime": datetime.datetime(2008, 11, 3, 15, 25, 30, 526),
"usedNames": ["Bobby"],
Expand Down Expand Up @@ -505,7 +505,7 @@ def test_df_get_recursive_join(conn_db_readonly: ConnDB) -> None:
},
"someMap": {"a": "b"},
"validInterval": datetime.timedelta(
days=3750, seconds=46800, microseconds=24
days=3800, seconds=46800, microseconds=24
),
},
{
Expand All @@ -529,7 +529,7 @@ def test_df_get_recursive_join(conn_db_readonly: ConnDB) -> None:
},
"someMap": {"a": "b"},
"validInterval": datetime.timedelta(
days=3750, seconds=46800, microseconds=24
days=3800, seconds=46800, microseconds=24
),
},
],
Expand Down
24 changes: 12 additions & 12 deletions test/test_networkx.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def test_to_networkx_node(conn_db_readonly: ConnDB) -> None:
Timestamp("2023-02-21 13:25:30"),
],
"lastJobDuration": [
Timedelta("1082 days 13:02:00"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("0 days 00:18:00.024000"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1082 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
],
"workedHours": [
[10, 5],
Expand Down Expand Up @@ -170,14 +170,14 @@ def test_networkx_undirected(conn_db_readonly: ConnDB) -> None:
Timestamp("2023-02-21 13:25:30"),
],
"lastJobDuration": [
Timedelta("1082 days 13:02:00"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
Timedelta("0 days 00:18:00.024000"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("1082 days 13:02:00"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("1097 days 13:02:00"),
],
"workedHours": [
[10, 5],
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_networkx_directed(conn_db_readonly: ConnDB) -> None:
],
"lastJobDuration": [
Timedelta("48 hours 24 minutes 11 seconds"),
Timedelta("3750 days 13:00:00.000024"),
Timedelta("3800 days 13:00:00.000024"),
Timedelta("2 days 00:24:11"),
],
"workedHours": [[4, 5], [1, 9], [2]],
Expand Down Expand Up @@ -315,7 +315,7 @@ def test_networkx_directed(conn_db_readonly: ConnDB) -> None:
"score": [-100, 7],
"history": ["2 years 4 days 10 hours", "2 years 4 hours 22 us 34 minutes"],
"licenseValidInterval": [
Timedelta(days=9414),
Timedelta(days=9544),
Timedelta(days=3, seconds=36000, microseconds=100000),
],
"rating": [0.78, 0.52],
Expand Down
Loading