Skip to content

Conversion to time zone aware time series: example#634

Merged
tnoczyns-volue merged 17 commits into
masterfrom
arkadiuszlis/tz-convert-example
Jun 5, 2026
Merged

Conversion to time zone aware time series: example#634
tnoczyns-volue merged 17 commits into
masterfrom
arkadiuszlis/tz-convert-example

Conversation

@arkadiuszlis
Copy link
Copy Markdown
Collaborator

@arkadiuszlis arkadiuszlis commented Jun 3, 2026

Add an example script

  • The script description contains 2 situations found in one of the internal DBs where points were misaligned to the DB zone
  • The script has a validation function which should be ran before attempting to convert ts to time zone aware
  • The script fixes the situations presented in the description and converts the ts to time zone aware and back
  • Add a documentation page on time zone aware ts with a reference to the example

Refers to https://github.com/Volue/energy-mesh/issues/8332

@arkadiuszlis
Copy link
Copy Markdown
Collaborator Author

Need to adjust the script to the simple thermal model, closing for now

@arkadiuszlis
Copy link
Copy Markdown
Collaborator Author

Decided to add a try-except block to mute the exception like we do in inflow and simulation examples

@arkadiuszlis arkadiuszlis reopened this Jun 5, 2026
Comment thread docs/source/time_zone_aware_timeseries.rst Outdated
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
Comment on lines +201 to +209
if validate_points_alignment(session=session, ts_key=TS_KEYS[0]) == False:
fix_ts_1111(session)
convert_to_time_zone_aware(session, TS_KEYS[0])
convert_to_time_zone_naive(session, TS_KEYS[0])

if validate_points_alignment(session=session, ts_key=TS_KEYS[1]) == False:
fix_ts_2222(session)
convert_to_time_zone_aware(session, TS_KEYS[1])
convert_to_time_zone_naive(session, TS_KEYS[1])
Copy link
Copy Markdown
Collaborator

@martingalvan-volue martingalvan-volue Jun 5, 2026

Choose a reason for hiding this comment

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

I think this would be equivalent:

Suggested change
if validate_points_alignment(session=session, ts_key=TS_KEYS[0]) == False:
fix_ts_1111(session)
convert_to_time_zone_aware(session, TS_KEYS[0])
convert_to_time_zone_naive(session, TS_KEYS[0])
if validate_points_alignment(session=session, ts_key=TS_KEYS[1]) == False:
fix_ts_2222(session)
convert_to_time_zone_aware(session, TS_KEYS[1])
convert_to_time_zone_naive(session, TS_KEYS[1])
fix_functions = {
1111: fix_ts_1111,
2222: fix_ts_2222,
}
for ts_key, fix_ts_points in fix_functions.items():
if validate_points_alignment(session, ts_key) == False:
fix_ts_points(session)
convert_to_time_zone_aware(session, ts_key)
convert_to_time_zone_naive(session, ts_key)

Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py
Comment on lines +174 to +181
aligned = True
for timestamp in utc_time:
if timestamp.as_py().hour != DB_ZONE_MIDNIGHT_IN_UTC:
print(
f"Time series key {ts_key}: the timestamp {timestamp.as_py()} is not aligned to the DB time zone midnight"
)
aligned = False
break
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is simpler:

Suggested change
aligned = True
for timestamp in utc_time:
if timestamp.as_py().hour != DB_ZONE_MIDNIGHT_IN_UTC:
print(
f"Time series key {ts_key}: the timestamp {timestamp.as_py()} is not aligned to the DB time zone midnight"
)
aligned = False
break
misaligned = next((timestamp for timestamp in utc_time if timestamp.as_py().hour != DB_ZONE_MIDNIGHT_IN_UTC), None)
if misaligned:
print(f"Time series key {ts_key}: the timestamp {timestamp.as_py()} is not aligned to the DB time zone midnight")
return misaligned != None

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it's just more pythonic

Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
Comment thread src/volue/mesh/examples/convert_to_time_zone_aware_timeseries.py Outdated
@tnoczyns-volue tnoczyns-volue merged commit 3324a1b into master Jun 5, 2026
11 checks passed
@tnoczyns-volue tnoczyns-volue deleted the arkadiuszlis/tz-convert-example branch June 5, 2026 15:06
@tnoczyns-volue tnoczyns-volue added this to the Version 1.17 milestone Jun 5, 2026
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.

3 participants