Skip to content

Commit 7de24b4

Browse files
committed
Make sure dates returned from prenight index bucket are dates, not strings
1 parent 261133f commit 7de24b4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

rubin_sim/sim_archive/prenightindex.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ def get_prenight_index_from_bucket(
137137

138138
prenights.index.name = "visitseq_uuid"
139139

140+
# Dates in json are loaded into strings, but in the
141+
# DB query code they are returned as instances of
142+
# datetime.date.
143+
# Convert correctly formatted date strings to datetime.date
144+
# so they come back the same regardless of origin.
145+
date_keys = ("sim_creation_day_obs", "first_day_obs", "last_day_obs", "parent_last_day_obs")
146+
for key in date_keys:
147+
replacement_values = None
148+
try:
149+
replacement_values = pd.to_datetime(prenights[key]).dt.date
150+
except (ValueError, KeyError):
151+
pass
152+
if replacement_values is not None:
153+
prenights[key] = replacement_values
154+
140155
return prenights
141156

142157

0 commit comments

Comments
 (0)