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

Improve performance of from_ordinal of temporal types. #1046

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

robsdedude
Copy link
Member

Speeds up the function by about a factor of 100
(depending on the exact ordinal chose).

Speeds up the function by about a factor of 100
(depending on the exact ordinal chose).

Signed-off-by: Grant Lodge <6323995+thelonelyvulpes@users.noreply.github.com>
Copy link
Contributor

@bigmontz bigmontz left a comment

Choose a reason for hiding this comment

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

🍏

(However, there is no tested related to the from_ordinal function in the code base)

@robsdedude
Copy link
Member Author

robsdedude commented Apr 24, 2024

There actually are tests 😇

def test_zero_ordinal(self) -> None:
d = Date.from_ordinal(0)
assert d.year_month_day == (0, 0, 0)
assert d.year == 0
assert d.month == 0
assert d.day == 0
assert d is ZeroDate
def test_ordinal_at_start_of_1970(self) -> None:
d = Date.from_ordinal(719163)
assert d.year_month_day == (1970, 1, 1)
assert d.year == 1970
assert d.month == 1
assert d.day == 1
def test_ordinal_at_end_of_1969(self) -> None:
d = Date.from_ordinal(719162)
assert d.year_month_day == (1969, 12, 31)
assert d.year == 1969
assert d.month == 12
assert d.day == 31
def test_ordinal_at_start_of_2018(self) -> None:
d = Date.from_ordinal(736695)
assert d.year_month_day == (2018, 1, 1)
assert d.year == 2018
assert d.month == 1
assert d.day == 1
def test_ordinal_at_end_of_2017(self) -> None:
d = Date.from_ordinal(736694)
assert d.year_month_day == (2017, 12, 31)
assert d.year == 2017
assert d.month == 12
assert d.day == 31

Their exhaustiveness is very debatable though ;)

@robsdedude robsdedude merged commit ca26531 into neo4j:5.0 Apr 24, 2024
20 checks passed
@robsdedude robsdedude deleted the fix/from-ordinal-performance branch April 24, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants