-
Notifications
You must be signed in to change notification settings - Fork 5
Added timezone handling including unit tests, tried for backwards compatibility #138
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?
Added timezone handling including unit tests, tried for backwards compatibility #138
Conversation
transformer_thermal_model/schemas/thermal_model/input_profile.py
Outdated
Show resolved
Hide resolved
| if isinstance(obj, pd.DatetimeIndex) and obj.tz is not None: | ||
| # tz-aware: preserve original timezone | ||
| return np.array(obj.to_pydatetime(), dtype=object) | ||
| return obj.to_numpy(dtype="datetime64[ns]") |
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.
For which types do you want this return to happen?
| if isinstance(obj, pd.DatetimeIndex) and obj.tz is not None: | ||
| # tz-aware: preserve original timezone | ||
| return np.array(obj.to_pydatetime(), dtype=object) | ||
| return obj.to_numpy(dtype="datetime64[ns]") |
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.
I prefer the try-catch to be removed. Maybe it is better and more readable to do:
if..
elif
else
raise type error
Because by doing it like that you know exactly when a error is raised. now it could also be another problem being catched by the try-except construction
transformer_thermal_model/schemas/thermal_model/input_profile.py
Outdated
Show resolved
Hide resolved
| if all(hasattr(x, "tzinfo") for x in obj): | ||
| return np.array(obj, dtype=object) | ||
| else: | ||
| return np.array(obj, dtype="datetime64[ns]") |
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.
why return this specific dtype and not the dtype of the original obj?
this does not agree with your idea of backwards compatible i guess .
Does this work ?
| return np.array(obj, dtype="datetime64[ns]") | |
| return np.array(obj, dtype=obj.dtype) |
| if isinstance(obj, pd.DatetimeIndex) and obj.tz is not None: | ||
| # tz-aware: preserve original timezone | ||
| return np.array(obj.to_pydatetime(), dtype=object) | ||
| return obj.to_numpy(dtype="datetime64[ns]") |
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.
again: Why convert to this specific dtype?
Maybe it would be better to use the original dtype?
…patibility Signed-off-by: Roos Schellevis <[email protected]>
Signed-off-by: Roos Schellevis <[email protected]>
Signed-off-by: Roos Schellevis <[email protected]>
109b846 to
7892a49
Compare
Added functionality to ensure timezones are retained from input profiles.
Tested both the array and df input options, adjusted error handling when incorrect data is provided for dates.
fixes #118