Added timezone handling including unit tests, tried for backwards compatibility#138
Draft
RoosSchellevis wants to merge 4 commits intoalliander-opensource:mainfrom
Draft
Conversation
anna-van-velsen
requested changes
Nov 25, 2025
| 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]") |
Contributor
There was a problem hiding this comment.
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]") |
Contributor
There was a problem hiding this comment.
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
| if all(hasattr(x, "tzinfo") for x in obj): | ||
| return np.array(obj, dtype=object) | ||
| else: | ||
| return np.array(obj, dtype="datetime64[ns]") |
Contributor
There was a problem hiding this comment.
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 ?
Suggested change
| 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]") |
Contributor
There was a problem hiding this comment.
again: Why convert to this specific dtype?
Maybe it would be better to use the original dtype?
…patibility Signed-off-by: Roos Schellevis <roos.schellevis@tennet.eu>
Signed-off-by: Roos Schellevis <roos.schellevis@tennet.eu>
Signed-off-by: Roos Schellevis <roos.schellevis@tennet.eu>
109b846 to
7892a49
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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