GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — wip · adjust/deepdiff@72393b8

This repository was archived by the owner on Dec 11, 2023. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deepdiff
    • commands.py
    • diff.py
    • serialization.py
  • tests
    • test_command.py
    • test_diff_text.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deepdiff/commands.py‎

Copy file name to clipboardExpand all lines: deepdiff/commands.py
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
CUTOFF_INTERSECTION_FOR_PAIRS_DEFAULT,
99
logger
1010
)
11-
from deepdiff import Delta, DeepSearch, extract
11+
from deepdiff import Delta, DeepSearch, extract as deep_extract
1212
from deepdiff.serialization import load_path_content, save_content_to_path
1313

1414

@@ -30,6 +30,7 @@ def cli():
3030
@click.option('--exclude-paths', required=False, type=str, show_default=False, multiple=True)
3131
@click.option('--exclude-regex-paths', required=False, type=str, show_default=False, multiple=True)
3232
@click.option('--get-deep-distance', is_flag=True, show_default=True)
33+
@click.option('--group-by', required=False, type=str, show_default=False, multiple=False)
3334
@click.option('--ignore-order', is_flag=True, show_default=True)
3435
@click.option('--ignore-string-type-changes', is_flag=True, show_default=True)
3536
@click.option('--ignore-numeric-type-changes', is_flag=True, show_default=True)
@@ -99,7 +100,7 @@ def diff(
99100
@click.argument('path', type=click.Path(exists=True, resolve_path=True))
100101
@click.argument('delta_path', type=click.Path(exists=True, resolve_path=True))
101102
@click.option('--backup', '-b', is_flag=True, show_default=True)
102-
def deeppatch(
103+
def patch(
103104
path, delta_path, backup
104105
):
105106
try:
@@ -150,7 +151,7 @@ def deeppatch(
150151
@click.option('--exclude-paths', required=False, type=str, show_default=False, multiple=True)
151152
@click.option('--exclude-regex-paths', required=False, type=str, show_default=False, multiple=True)
152153
@click.option('--verbose-level', required=False, default=1, type=click.IntRange(0, 2), show_default=True)
153-
def deepgrep(item, path, **kwargs):
154+
def grep(item, path, **kwargs):
154155
kwargs['case_sensitive'] = not kwargs.pop('ignore_case')
155156
kwargs['match_string'] = kwargs.pop('exact_match')
156157

@@ -169,7 +170,7 @@ def deepgrep(item, path, **kwargs):
169170
@cli.command()
170171
@click.argument('path_inside', required=True, type=str)
171172
@click.argument('path', type=click.Path(exists=True, resolve_path=True))
172-
def deepextract(path_inside, path):
173+
def extract(path_inside, path):
173174
"""
174175
Deep Extract
175176
"""
@@ -179,7 +180,7 @@ def deepextract(path_inside, path):
179180
sys.exit(str(f"Error when loading {path}: {e}"))
180181

181182
try:
182-
result = extract(content, path_inside)
183+
result = deep_extract(content, path_inside)
183184
except Exception as e:
184185
sys.exit(str(f"Error when running deep search on {path}: {e}"))
185186
pprint(result, indent=2)
Collapse file

‎deepdiff/diff.py‎

Copy file name to clipboardExpand all lines: deepdiff/diff.py
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def __init__(self,
114114
exclude_types=None,
115115
exclude_obj_callback=None,
116116
get_deep_distance=False,
117+
group_by=None,
117118
hasher=None,
118119
hashes=None,
119120
ignore_order=False,
@@ -149,7 +150,7 @@ def __init__(self,
149150
"ignore_private_variables, ignore_nan_inequality, number_to_string_func, verbose_level, "
150151
"view, hasher, hashes, max_passes, max_diffs, "
151152
"cutoff_distance_for_pairs, cutoff_intersection_for_pairs, log_frequency_in_sec, cache_size, "
152-
"cache_tuning_sample_size, get_deep_distance, cache_purge_level, "
153+
"cache_tuning_sample_size, get_deep_distance, group_by, cache_purge_level, "
153154
"_original_type, _parameters and _shared_parameters.") % ', '.join(kwargs.keys()))
154155

155156
if _parameters:
@@ -248,8 +249,18 @@ def __init__(self,
248249
self._parameters = _parameters
249250
self.deephash_parameters = self.__get_deephash_params()
250251
self.tree = TreeResult()
251-
self.t1 = t1
252-
self.t2 = t2
252+
if group_by:
253+
try:
254+
t1 = self.t1 = {row[group_by]: row for row in t1}
255+
except KeyError:
256+
logger.error("can not group t1 by {}".format(group_by))
257+
try:
258+
t2 = self.t2 = {row[group_by]: row for row in t2}
259+
except KeyError:
260+
logger.error("can not group t2 by {}".format(group_by))
261+
else:
262+
self.t1 = t1
263+
self.t2 = t2
253264

254265
try:
255266
root = DiffLevel(t1, t2, verbose_level=self.verbose_level)
Collapse file

‎deepdiff/serialization.py‎

Copy file name to clipboardExpand all lines: deepdiff/serialization.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ def load_path_content(path, file_type=None):
346346
if clevercsv is None: # pragma: no cover.
347347
raise ImportError('CleverCSV needs to be installed.') # pragma: no cover.
348348
content = clevercsv.read_dicts(path)
349+
350+
# Everything in csv is string but we try to automatically convert any numbers we find
351+
for row in content:
352+
for key, value in row.items():
353+
value = value.strip()
354+
for type_ in [int, float, complex]:
355+
try:
356+
value = type_(value)
357+
except Exception:
358+
pass
359+
else:
360+
row[key] = value
361+
break
349362
else:
350363
raise UnsupportedFormatErr(f'Only json, yaml, toml, csv, tsv and pickle are supported.\n'
351364
f' The {file_type} extension is not known.')
Collapse file

‎tests/test_command.py‎

Copy file name to clipboardExpand all lines: tests/test_command.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
from shutil import copyfile
44
from click.testing import CliRunner
5-
from deepdiff.commands import diff, deeppatch
5+
from deepdiff.commands import diff, patch
66
from conftest import FIXTURES_DIR
77
from deepdiff.helper import pypy3
88

@@ -59,7 +59,7 @@ def test_deeppatch_command(self, t1, t2, args, expected_exit_code):
5959
the_file.write(delta_pickled.stdout_bytes)
6060

6161
runner = CliRunner()
62-
deeppatched = runner.invoke(deeppatch, [t1_copy_path, delta_path])
62+
deeppatched = runner.invoke(patch, [t1_copy_path, delta_path])
6363
assert deeppatched.exit_code == expected_exit_code
6464

6565
runner = CliRunner()
Collapse file

‎tests/test_diff_text.py‎

Copy file name to clipboardExpand all lines: tests/test_diff_text.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ def test_int_to_unicode(self):
986986
assert result == ddiff
987987

988988
@pytest.mark.parametrize("t1, t2, ignore_numeric_type_changes, significant_digits, number_format_notation, result", [
989+
(43.265798602382986, 43.71677762295505, False, 0, "f", {'values_changed': {'root': {'new_value': 43.71677762295505, 'old_value': 43.265798602382986}}}), # Note that it rounds the number so one becomes 43 and the other one is 44
989990
(Decimal('2.5'), Decimal('1.5'), False, 0, "f", {}),
990991
(Decimal('2.5'), Decimal('1.5'), False, 1, "f", {'values_changed': {'root': {'new_value': Decimal('1.5'), 'old_value': Decimal('2.5')}}}),
991992
(Decimal('2.5'), Decimal(2.5), False, 3, "f", {}),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.