-
Notifications
You must be signed in to change notification settings - Fork 7
Time zone localization #61
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces time zone localization functionality to handle conversion of timezone-naive (TIMESTAMP_NTZ) timestamps to timezone-aware (TIMESTAMP_TZ) timestamps. The changes include new localizer classes, refactoring of time configuration models, updates to test utilities, and bug fixes.
Changes:
- Added
TimeZoneLocalizerandTimeZoneLocalizerByColumnclasses for localizing tz-naive timestamps to standard time zones - Refactored time configuration models to include
dtypefield and consolidatedIndexTimeRangeclasses - Updated test utilities and fixed API inconsistencies (
np.concat→np.concatenate)
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/chronify/time_zone_localizer.py | New module implementing time zone localization classes and functions |
| src/chronify/time_configs.py | Added dtype field to DatetimeRange classes and consolidated IndexTimeRange classes |
| src/chronify/time.py | Replaced DatetimeFormat with TimeDataType enum |
| src/chronify/store.py | Added localize_time_zone and localize_time_zone_by_column methods |
| src/chronify/time_zone_converter.py | Updated error messages and added dtype field usage |
| src/chronify/datetime_range_generator.py | Refactored timestamp generation to use pd.date_range and improved handling of time zones |
| src/chronify/sqlalchemy/functions.py | Updated to use dtype field instead of start_time_is_tz_naive() |
| src/chronify/time_series_mapper_index_time.py | Added dtype field assignment in mapping creation |
| src/chronify/time_series_checker.py | Fixed typo in docstring |
| tests/test_time_zone_localizer.py | Comprehensive test coverage for new localization functionality |
| tests/test_store.py | Integration tests for localize_time_zone methods |
| tests/test_time_zone_converter.py | Updated error message test and refactored test utilities |
| tests/test_mapper_*.py | Refactored to use list_timestamps() instead of _iter_timestamps() |
| tests/test_mapper_column_representative_to_datetime.py | Fixed np.concat → np.concatenate |
| src/chronify/init.py | Updated exports to remove deprecated IndexTimeRange classes |
| docs/how_tos/map_time_config.md | Fixed np.concat → np.concatenate in documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
daniel-thom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good; just some minor comments to clean up.
| Note: Established time library already handles historical changes in time zone conversion to UTC. | ||
| (e.g. Algeria (Africa/Algiers) changed from UTC+0 to UTC+1 on April 25, 1980) | ||
| """ | ||
| for ts in self._list_timestamps(start=start): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are removing the feature of lazy iteration, we should remove this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it needed for polymorism? All generators have this method and it is used by a mapper here:
chronify/src/chronify/time_series_mapper_column_representative_to_datetime.py
Lines 196 to 198 in 8db9fae
| def _iter_datetime(self) -> Generator[datetime, None, None]: | |
| datetime_generator = DatetimeRangeGenerator(self._to_time_config) | |
| yield from datetime_generator._iter_timestamps() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it needed for polymorism? All generators have this method and it is used by a mapper here:
chronify/src/chronify/time_series_mapper_column_representative_to_datetime.py
Lines 196 to 198 in 8db9fae
def _iter_datetime(self) -> Generator[datetime, None, None]: datetime_generator = DatetimeRangeGenerator(self._to_time_config) yield from datetime_generator._iter_timestamps()
The base class only requires this method:
@abc.abstractmethod
def list_timestamps(self) -> list[Any]:
Provides time zone localization support.
Integration into dsgrid: dsgrid/dsgrid#406