-
-
Notifications
You must be signed in to change notification settings - Fork 238
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
DeepDiff Fails to Detect Timezone Changes in Arrays with ignore_order=True
#516
Comments
ignore_order=True
ignore_order=True
@3schwartz We only assume the UTC timezone if the datetime is not timezone aware. If the datetime is timezone aware, we don't overwrite it. Also you are using an older version of DeepDiff. |
What are your reasons for such peculiar default behaviour? This would be a useful option, but having this as the default behaviour is just wrong. |
@chriswyatt The reason was so you get deterministic diff regardless of your local timezone. |
What we can do is to allow the user to pass a "default" timezone if the datetime values are not timezone native. And our default will be UTC unless the user overrides it. |
UTC and local system time are the only ones that really make sense when it comes to naive datetimes. Python assumes local time by default, so defaulting to UTC is just not the expected behaviour. It's particularly confusing here in the UK, where we might write some code that works fine in the winter, and then it will suddenly not work correctly in the summer. The problem with assuming other timezones, is that a lot of countries use 2 timezones depending on the time of year. That would be quite a bit of extra complication and test coverage needed. It doesn't seem like a feature that many would need, so I would personally avoid it, myself. I do appreciate the feature though. The projects I'm working on right now do use naive UTC quite a lot, so this feature is really useful to me. |
@chriswyatt Thanks. I added the Default Timezone parameter: https://zepworks.com/deepdiff/current/basics.html#default-time-zone |
Describe the bug
The
deepdiff
library is unable to detect timezone changes in datetimes within arrays.When
ignore_order=True
and a datetime is present within an array,deepdiff
uses an execution path that makes aDeepHash
. Due to the implementation ofdatetime_normalize
, all datetimes have their timezone set to UTC:deepdiff/deepdiff/helper.py
Line 627 in c718369
This behavior causes issues in our use case, as we rely on deepdiff to detect changes in datetime objects, including changes to their timezones.
To Reproduce
Here’s a minimal example demonstrating the issue. The data structure includes datetimes within an array. When the timezone of the datetimes is changed, deepdiff` does not recognize this change:
Execution path
Expected behavior
I expect
deepdiff
to detect changes to datetime objects, including differences in their timezones, and report the data structures as different.Is there a specific reason why datetime_normalize replaces the timezone with UTC? Would it be reasonable to modify or remove this behavior?
Alternatively, could the logic be adjusted to conditionally apply the timezone replacement only when
truncate_datetime
is explicitly set? For example, the following indentation could be introduced:This approach ensures that timezone replacement occurs only when
truncate_datetime
is explicitly set.A solution with the proposed approach mentioned above has been submitted in PR #517.
OS, DeepDiff version and Python version (please complete the following information):
The text was updated successfully, but these errors were encountered: