Skip to content

feat: Add time_zone to Datetime results #33

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dfrankland
Copy link

@dfrankland dfrankland commented May 7, 2025

Motivation

Closes #32

Changes

allows setting a time zone for datetimes and checking if the values in the column matches it

Pertinent polars docs:
https://docs.pola.rs/user-guide/transformations/time-series/timezones/

allows setting a time zone for datetimes and checking if the values in the column matches it
Comment on lines +351 to +379
(
dy.Date(),
[dt.date(2020, 1, 1), dt.date(2021, 1, 15), dt.date(2022, 12, 1)],
{},
),
(
dy.Date(resolution="1mo"),
[dt.date(2020, 1, 1), dt.date(2021, 1, 15), dt.date(2022, 12, 1)],
{"resolution": [True, False, True]},
),
(
dy.Time(),
[dt.time(12, 0), dt.time(13, 15), dt.time(14, 0, 5)],
{},
),
(
dy.Time(resolution="1h"),
[dt.time(12, 0), dt.time(13, 15), dt.time(14, 0, 5)],
{"resolution": [True, False, False]},
),
(
dy.Datetime(),
[
dt.datetime(2020, 4, 5),
dt.datetime(2021, 1, 1, 12),
dt.datetime(2022, 7, 10, 0, 0, 1),
],
{},
),
Copy link
Author

Choose a reason for hiding this comment

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

I added these since I wanted to double-check the negative case when nothing is specified, but I'm happy to remove them if you believe these are too verbose

Copy link
Member

Choose a reason for hiding this comment

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

I find it a little confusing to have these cases here. The test is named test_validate_resolution after all. I'd propose to remove

@dfrankland dfrankland changed the title add time_zone to Datetime results feat: add time_zone to Datetime results May 7, 2025
@github-actions github-actions bot added the enhancement New feature or request label May 7, 2025
Copy link

codecov bot commented May 9, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.89%. Comparing base (6c955c4) to head (30e3538).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
dataframely/columns/datetime.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main      #33      +/-   ##
===========================================
- Coverage   100.00%   99.89%   -0.11%     
===========================================
  Files           38       38              
  Lines         1845     1852       +7     
===========================================
+ Hits          1845     1850       +5     
- Misses           0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@AndreasAlbertQC AndreasAlbertQC left a comment

Choose a reason for hiding this comment

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

Thanks for the nice PR @dfrankland! Could you add a test in test_sql_schema.py for the oracle part?

@dfrankland dfrankland requested a review from AndreasAlbertQC May 9, 2025 21:46
Copy link
Member

@borchero borchero left a comment

Choose a reason for hiding this comment

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

Thanks for the initiative @dfrankland, I think this is a very useful addition! :)

@borchero borchero changed the title feat: add time_zone to Datetime results feat: Add time_zone to Datetime results May 9, 2025
@dfrankland
Copy link
Author

Let me know if you'd like for me to rebase these changes

@dfrankland dfrankland requested a review from borchero May 9, 2025 23:56
@dfrankland dfrankland force-pushed the add-time_zone-to-datetime-results branch from 8de8c8f to 30e3538 Compare May 10, 2025 00:28
Copy link
Member

@borchero borchero left a comment

Choose a reason for hiding this comment

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

All right, nice, I think we're almost there! :)

return sa_mssql.DATETIME2(6)
return sa_mssql.DATETIME2(6, timezone=timezone_enabled)
case "postgresql":
return sa_postgresql.TIMESTAMP(timezone=timezone_enabled)
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this extra condition for postgres or does sa.DateTime(timezone=timezone_enabled) map to TIMESTAMPTZ anyways? We're currently not maintaining 100% coverage (which we should) because we're not using the default case.

Comment on lines +351 to +379
(
dy.Date(),
[dt.date(2020, 1, 1), dt.date(2021, 1, 15), dt.date(2022, 12, 1)],
{},
),
(
dy.Date(resolution="1mo"),
[dt.date(2020, 1, 1), dt.date(2021, 1, 15), dt.date(2022, 12, 1)],
{"resolution": [True, False, True]},
),
(
dy.Time(),
[dt.time(12, 0), dt.time(13, 15), dt.time(14, 0, 5)],
{},
),
(
dy.Time(resolution="1h"),
[dt.time(12, 0), dt.time(13, 15), dt.time(14, 0, 5)],
{"resolution": [True, False, False]},
),
(
dy.Datetime(),
[
dt.datetime(2020, 4, 5),
dt.datetime(2021, 1, 1, 12),
dt.datetime(2022, 7, 10, 0, 0, 1),
],
{},
),
Copy link
Member

Choose a reason for hiding this comment

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

I find it a little confusing to have these cases here. The test is named test_validate_resolution after all. I'd propose to remove

),
],
)
def test_dtype_validation(
Copy link
Member

Choose a reason for hiding this comment

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

[nit]

Suggested change
def test_dtype_validation(
def test_dtype_time_zone_validation(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dy.Datetime() does not support time_unit and time_zone
3 participants