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

Python: Add support date, time and datetime in to_bytes #8214

Merged
merged 10 commits into from
Aug 4, 2023

Conversation

onerishabh
Copy link
Contributor

@onerishabh onerishabh commented Aug 3, 2023

  • Enable converting objects of date, time and datetime types to bytes.
  • Uses pyiceberg/utils/datetime.py functions to convert date/timestamp to epoch microseconds.
  • Uses _LONG_STRUCT to pack epoch microseconds.
  • Uses _INT_STRUCT to pack number of days since epoch.

Test Cases (epoch microseconds used for testing):

  • datetime(2023, 3, 1, 19, 25, 0)
  • datetime(2023, 3, 1, 19, 25, 0, tzinfo=timezone.utc)
  • date(2023, 3, 1)
  • time(12, 30, 45, 500000)

Issue: #8191

@github-actions github-actions bot added the python label Aug 3, 2023
@Fokko
Copy link
Contributor

Fokko commented Aug 3, 2023

This is great @onerishabh, can you throw in some tests in test_conversions.py?

@onerishabh
Copy link
Contributor Author

onerishabh commented Aug 3, 2023

This is great @onerishabh, can you throw in some tests in test_conversions.py?

@Fokko tests added as well

@Fokko
Copy link
Contributor

Fokko commented Aug 3, 2023

@onerishabh Sorry, I was not specific about the testing. I think we're super close, but I would love to see tests like:

to_bytes(DateType(), date(1925, 1, 1)) == b"..."

For the date, time and datetime

@onerishabh
Copy link
Contributor Author

@Fokko , have a look now. Added a new function to do this testing!

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

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

@onerishabh Thanks, exactly the tests that I was looking for, thank you for working on this 🙏🏻

@Fokko Fokko merged commit b34f4f2 into apache:master Aug 4, 2023
7 checks passed
@onerishabh
Copy link
Contributor Author

Wohoooo 🎉

@onerishabh onerishabh deleted the python-datetime-support-to_bytes branch August 10, 2023 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants