Skip to content

Commit 69c7b5c

Browse files
authored
Merge pull request #514 from seperman/dev
8.2.0
2 parents c718369 + eed7669 commit 69c7b5c

17 files changed

+204
-147
lines changed

.github/workflows/main.yaml

+11-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
15+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1616
architecture: ["x64"]
1717
steps:
1818
- uses: actions/checkout@v2
@@ -23,7 +23,7 @@ jobs:
2323
architecture: ${{ matrix.architecture }}
2424
- name: Cache pip 3.8
2525
if: matrix.python-version == 3.8
26-
uses: actions/cache@v2
26+
uses: actions/cache@v4
2727
with:
2828
# This path is specific to Ubuntu
2929
path: ~/.cache/pip
@@ -34,7 +34,9 @@ jobs:
3434
${{ runner.os }}-
3535
- name: Cache pip
3636
if: matrix.python-version != 3.8
37-
uses: actions/cache@v2
37+
env:
38+
PYO3_USE_ABI3_FORWARD_COMPATIBILITY: "1"
39+
uses: actions/cache@v4
3840
with:
3941
# This path is specific to Ubuntu
4042
path: ~/.cache/pip
@@ -44,9 +46,9 @@ jobs:
4446
${{ runner.os }}-pip-
4547
${{ runner.os }}-
4648
- name: Upgrade setuptools
47-
if: matrix.python-version => 3.12
49+
if: matrix.python-version >= 3.12
4850
run: |
49-
# workaround for 3.13, SEE: https://github.com/pypa/setuptools/issues/3661#issuecomment-1813845177
51+
# workaround for 3.12, SEE: https://github.com/pypa/setuptools/issues/3661#issuecomment-1813845177
5052
pip install --upgrade setuptools
5153
- name: Install dependencies
5254
if: matrix.python-version > 3.9
@@ -55,23 +57,23 @@ jobs:
5557
if: matrix.python-version <= 3.9
5658
run: pip install -r requirements-dev3.8.txt
5759
- name: Lint with flake8
58-
if: matrix.python-version == 3.13
60+
if: matrix.python-version == 3.12
5961
run: |
6062
# stop the build if there are Python syntax errors or undefined names
6163
flake8 deepdiff --count --select=E9,F63,F7,F82 --show-source --statistics
6264
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
6365
flake8 deepdiff --count --exit-zero --max-complexity=26 --max-line-lengt=250 --statistics
6466
- name: Test with pytest and get the coverage
65-
if: matrix.python-version == 3.13
67+
if: matrix.python-version == 3.12
6668
run: |
6769
pytest --benchmark-disable --cov-report=xml --cov=deepdiff tests/ --runslow
6870
- name: Test with pytest and no coverage report
69-
if: matrix.python-version != 3.13
71+
if: matrix.python-version != 3.12
7072
run: |
7173
pytest --benchmark-disable
7274
- name: Upload coverage to Codecov
7375
uses: codecov/codecov-action@v4
74-
if: matrix.python-version == 3.13
76+
if: matrix.python-version == 3.12
7577
env:
7678
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7779
with:

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# DeepDiff Change log
22

3+
- v8-2-0
4+
- Small optimizations so we don't load functions that are not needed
5+
- Updated the minimum version of Orderly-set
6+
- Normalize all datetimes into UTC. Assume timezone naive datetimes are UTC.
37

48
- v8-1-0
59
- Removing deprecated lines from setup.py

README.md

+6-50
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Tested on Python 3.8+ and PyPy3.
2323

2424
Please check the [ChangeLog](CHANGELOG.md) file for the detailed information.
2525

26+
DeepDiff 8-2-0
27+
28+
- Small optimizations so we don't load functions that are not needed
29+
- Updated the minimum version of Orderly-set
30+
- Normalize all datetimes into UTC. Assume timezone naive datetimes are UTC.
31+
2632
DeepDiff 8-1-0
2733

2834
- Removing deprecated lines from setup.py
@@ -40,56 +46,6 @@ DeepDiff 8-1-0
4046
- Fixes accessing the affected_root_keys property on the diff object returned by DeepDiff fails when one of the dicts is empty
4147
- Fixes accessing the affected_root_keys property on the diff object returned by DeepDiff fails when one of the dicts is empty #508
4248

43-
DeepDiff 8-0-1
44-
45-
- Bugfix. Numpy should be optional.
46-
47-
DeepDiff 8-0-0
48-
49-
With the introduction of `threshold_to_diff_deeper`, the values returned are different than in previous versions of DeepDiff. You can still get the older values by setting `threshold_to_diff_deeper=0`. However to signify that enough has changed in this release that the users need to update the parameters passed to DeepDiff, we will be doing a major version update.
50-
51-
- `use_enum_value=True` makes it so when diffing enum, we use the enum's value. It makes it so comparing an enum to a string or any other value is not reported as a type change.
52-
- `threshold_to_diff_deeper=float` is a number between 0 and 1. When comparing dictionaries that have a small intersection of keys, we will report the dictionary as a `new_value` instead of reporting individual keys changed. If you set it to zero, you get the same results as DeepDiff 7.0.1 and earlier, which means this feature is disabled. The new default is 0.33 which means if less that one third of keys between dictionaries intersect, report it as a new object.
53-
- Deprecated `ordered-set` and switched to `orderly-set`. The `ordered-set` package was not being maintained anymore and starting Python 3.6, there were better options for sets that ordered. I forked one of the new implementations, modified it, and published it as `orderly-set`.
54-
- Added `use_log_scale:bool` and `log_scale_similarity_threshold:float`. They can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits.
55-
- json serialization of reversed lists.
56-
- Fix for iterable moved items when `iterable_compare_func` is used.
57-
- Pandas and Polars support.
58-
59-
DeepDiff 7-0-1
60-
61-
- Fixes the translation between Difflib opcodes and Delta flat rows.
62-
63-
DeepDiff 7-0-0
64-
65-
- DeepDiff 7 comes with an improved delta object. [Delta to flat dictionaries](https://zepworks.com/deepdiff/current/serialization.html#delta-serialize-to-flat-dictionaries) have undergone a major change. We have also introduced [Delta serialize to flat rows](https://zepworks.com/deepdiff/current/serialization.html#delta-serialize-to-flat-rows).
66-
- Subtracting delta objects have dramatically improved at the cost of holding more metadata about the original objects.
67-
- When `verbose=2`, and the "path" of an item has changed in a report between t1 and t2, we include it as `new_path`.
68-
- `path(use_t2=True)` returns the correct path to t2 in any reported change in the [`tree view`](https://zepworks.com/deepdiff/current/view.html#tree-view)
69-
- Python 3.7 support is dropped and Python 3.12 is officially supported.
70-
71-
72-
DeepDiff 6-7-1
73-
74-
- Support for subtracting delta objects when iterable_compare_func is used.
75-
- Better handling of force adding a delta to an object.
76-
- Fix for [`Can't compare dicts with both single and double quotes in keys`](https://github.com/seperman/deepdiff/issues/430)
77-
- Updated docs for Inconsistent Behavior with math_epsilon and ignore_order = True
78-
79-
DeepDiff 6-7-0
80-
81-
- Delta can be subtracted from other objects now.
82-
- verify_symmetry is deprecated. Use bidirectional instead.
83-
- always_include_values flag in Delta can be enabled to include values in the delta for every change.
84-
- Fix for Delta.__add__ breaks with esoteric dict keys.
85-
- You can load a delta from the list of flat dictionaries.
86-
87-
DeepDiff 6-6-1
88-
89-
- Fix for [DeepDiff raises decimal exception when using significant digits](https://github.com/seperman/deepdiff/issues/426)
90-
- Introducing group_by_sort_key
91-
- Adding group_by 2D. For example `group_by=['last_name', 'zip_code']`
92-
9349

9450
## Installation
9551

deepdiff/diff.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import difflib
99
import logging
1010
import types
11+
import datetime
1112
from enum import Enum
1213
from copy import deepcopy
1314
from math import isclose as is_close
14-
from typing import List, Dict, IO, Callable, Set, Union, Any, Pattern, Tuple, Optional
15+
from typing import List, Dict, Callable, Union, Any, Pattern, Tuple, Optional
1516
from collections.abc import Mapping, Iterable, Sequence
1617
from collections import defaultdict
1718
from inspect import getmembers
1819
from itertools import zip_longest
20+
from functools import lru_cache
1921
from deepdiff.helper import (strings, bytes_type, numbers, uuids, datetimes, ListItemRemovedOrAdded, notpresent,
2022
IndexedHash, unprocessed, add_to_frozen_set, basic_types,
2123
convert_item_or_items_into_set_else_none, get_type,
@@ -1123,6 +1125,7 @@ def _create_hashtable(self, level, t):
11231125
return local_hashes
11241126

11251127
@staticmethod
1128+
@lru_cache(maxsize=2028)
11261129
def _get_distance_cache_key(added_hash, removed_hash):
11271130
key1, key2 = (added_hash, removed_hash) if added_hash > removed_hash else (removed_hash, added_hash)
11281131
if isinstance(key1, int):
@@ -1485,7 +1488,15 @@ def _diff_numbers(self, level, local_tree=None, report_type_change=True):
14851488
if t1_s != t2_s:
14861489
self._report_result('values_changed', level, local_tree=local_tree)
14871490

1488-
def _diff_datetimes(self, level, local_tree=None):
1491+
def _diff_datetime(self, level, local_tree=None):
1492+
"""Diff DateTimes"""
1493+
level.t1 = datetime_normalize(self.truncate_datetime, level.t1)
1494+
level.t2 = datetime_normalize(self.truncate_datetime, level.t2)
1495+
1496+
if level.t1 != level.t2:
1497+
self._report_result('values_changed', level, local_tree=local_tree)
1498+
1499+
def _diff_time(self, level, local_tree=None):
14891500
"""Diff DateTimes"""
14901501
if self.truncate_datetime:
14911502
level.t1 = datetime_normalize(self.truncate_datetime, level.t1)
@@ -1668,8 +1679,11 @@ def _diff(self, level, parents_ids=frozenset(), _original_type=None, local_tree=
16681679
elif isinstance(level.t1, strings):
16691680
self._diff_str(level, local_tree=local_tree)
16701681

1671-
elif isinstance(level.t1, datetimes):
1672-
self._diff_datetimes(level, local_tree=local_tree)
1682+
elif isinstance(level.t1, datetime.datetime):
1683+
self._diff_datetime(level, local_tree=local_tree)
1684+
1685+
elif isinstance(level.t1, (datetime.date, datetime.timedelta, datetime.time)):
1686+
self._diff_time(level, local_tree=local_tree)
16731687

16741688
elif isinstance(level.t1, uuids):
16751689
self._diff_uuids(level, local_tree=local_tree)

deepdiff/helper.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import sys
22
import re
33
import os
4-
import math
54
import datetime
65
import uuid
76
import logging
@@ -624,12 +623,29 @@ def datetime_normalize(truncate_datetime, obj):
624623
elif truncate_datetime == 'day':
625624
obj = obj.replace(hour=0, minute=0, second=0, microsecond=0)
626625
if isinstance(obj, datetime.datetime):
627-
obj = obj.replace(tzinfo=datetime.timezone.utc)
626+
if has_timezone(obj):
627+
obj = obj.astimezone(datetime.timezone.utc)
628+
else:
629+
obj = obj.replace(tzinfo=datetime.timezone.utc)
628630
elif isinstance(obj, datetime.time):
629631
obj = time_to_seconds(obj)
630632
return obj
631633

632634

635+
def has_timezone(dt):
636+
"""
637+
Function to check if a datetime object has a timezone
638+
639+
Checking dt.tzinfo.utcoffset(dt) ensures that the datetime object is truly timezone-aware
640+
because some datetime objects may have a tzinfo attribute that is not None but still
641+
doesn't provide a valid offset.
642+
643+
Certain tzinfo objects, such as pytz.timezone(None), can exist but do not provide meaningful UTC offset information.
644+
If tzinfo is present but calling .utcoffset(dt) returns None, the datetime is not truly timezone-aware.
645+
"""
646+
return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None
647+
648+
633649
def get_truncate_datetime(truncate_datetime):
634650
"""
635651
Validates truncate_datetime value

0 commit comments

Comments
 (0)