Skip to content

Commit 0a8a138

Browse files
feat: Show data types of one-sided columns in summary (#69)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a1f3045 commit 0a8a138

259 files changed

Lines changed: 1823 additions & 1752 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎diffly/summary.py‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ def to_json(self, **kwargs: Any) -> str:
117117
"right_name": "right",
118118
"primary_key": ["id"],
119119
"schemas": {
120-
"left_only_names": [],
120+
"left_only": [],
121121
"in_common": [["id", "Int64", "Int64"], ["value", "Float64", "Float64"]],
122-
"right_only_names": []
122+
"right_only": []
123123
},
124124
"rows": {
125125
"n_left": 3,
@@ -240,23 +240,25 @@ def _print_num_columns(n: int) -> str:
240240

241241
table = Table()
242242

243-
left_only_names = set(schemas.left_only_names)
244-
right_only_names = set(schemas.right_only_names)
245-
max_column_width = max(
246-
len(column) for column in left_only_names | right_only_names | {""}
247-
)
243+
left_only_dtypes = schemas.left_only
244+
right_only_dtypes = schemas.right_only
245+
missing_widths = [
246+
len(f"{col} [{dtype}]")
247+
for col, dtype in left_only_dtypes + right_only_dtypes
248+
]
249+
max_column_width = max(missing_widths, default=0)
248250

249-
if len(missing := left_only_names | right_only_names) > 0:
251+
if len(missing_widths) > 0:
250252
# NOTE: At least 10 as "in common" already has 9 chars
251-
min_width = max(10, *[len(col) for col in missing])
253+
min_width = max(10, *missing_widths)
252254
else:
253255
min_width = 0
254256

255257
table_data: dict[str, list[str]] = {}
256258

257259
# Left only
258-
if len(left_only_names) > 0:
259-
left_only_header = f"{capitalize_first(self._data._truncated_left_name)} only \n{_print_num_columns(len(left_only_names))}"
260+
if len(left_only_dtypes) > 0:
261+
left_only_header = f"{capitalize_first(self._data._truncated_left_name)} only \n{_print_num_columns(len(left_only_dtypes))}"
260262
table.add_column(
261263
left_only_header,
262264
header_style="red",
@@ -266,7 +268,7 @@ def _print_num_columns(n: int) -> str:
266268
overflow=OVERFLOW,
267269
)
268270
table_data[left_only_header] = [
269-
_format_colname(col) for col in sorted(left_only_names)
271+
f"{_format_colname(col)} [{dtype}]" for col, dtype in left_only_dtypes
270272
]
271273

272274
# In common
@@ -307,8 +309,8 @@ def _print_num_columns(n: int) -> str:
307309
)
308310

309311
# Right only
310-
if len(right_only_names) > 0:
311-
right_only_header = f"{capitalize_first(self._data._truncated_right_name)} only\n{_print_num_columns(len(right_only_names))}"
312+
if len(right_only_dtypes) > 0:
313+
right_only_header = f"{capitalize_first(self._data._truncated_right_name)} only\n{_print_num_columns(len(right_only_dtypes))}"
312314
table.add_column(
313315
right_only_header,
314316
header_style="green",
@@ -318,7 +320,7 @@ def _print_num_columns(n: int) -> str:
318320
overflow=OVERFLOW,
319321
)
320322
table_data[right_only_header] = [
321-
_format_colname(col) for col in sorted(right_only_names)
323+
f"{_format_colname(col)} [{dtype}]" for col, dtype in right_only_dtypes
322324
]
323325

324326
max_len = max(len(column_list) for column_list in table_data.values())
@@ -723,9 +725,9 @@ def _section_rows_only_one_side(self, side: Side) -> RenderableType:
723725

724726
@dataclass
725727
class SummaryDataSchemas:
726-
left_only_names: list[str]
728+
left_only: list[tuple[str, str]]
727729
in_common: list[tuple[str, str, str]]
728-
right_only_names: list[str]
730+
right_only: list[tuple[str, str]]
729731
_equal: bool
730732
_mismatching_dtypes: list[tuple[str, str, str]]
731733

@@ -949,12 +951,18 @@ def _compute_schemas(
949951
in_common = sorted(comp.schemas.in_common().items())
950952
mismatching = sorted(comp.schemas.in_common().mismatching_dtypes().items())
951953
return SummaryDataSchemas(
952-
left_only_names=sorted(comp.schemas.left_only().column_names()),
954+
left_only=[
955+
(name, str(dtype))
956+
for name, dtype in sorted(comp.schemas.left_only().items())
957+
],
953958
in_common=[
954959
(name, str(left_dtype), str(right_dtype))
955960
for name, (left_dtype, right_dtype) in in_common
956961
],
957-
right_only_names=sorted(comp.schemas.right_only().column_names()),
962+
right_only=[
963+
(name, str(dtype))
964+
for name, dtype in sorted(comp.schemas.right_only().items())
965+
],
958966
_equal=comp.schemas.equal(),
959967
_mismatching_dtypes=[
960968
(name, str(left_dtype), str(right_dtype))

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_False_slim_False_sample_rows_False_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
Schemas
88
▔▔▔▔▔▔▔
9-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
10-
┃ Left only ┃ In common ┃ Right only ┃
11-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
13-
│ col_a │ ... │ col_d │
14-
│ col_b │ │ │
15-
└────────────┴────────────┴────────────┘
9+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
10+
┃ Left only ┃ In common ┃ Right only ┃
11+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
13+
│ col_a [Null] │ ... │ col_d [Null] │
14+
│ col_b [Null] │ │ │
15+
└──────────────┴──────────────┴──────────────┘
1616

1717
Rows
1818
▔▔▔▔

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_False_slim_False_sample_rows_True_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
Schemas
88
▔▔▔▔▔▔▔
9-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
10-
┃ Left only ┃ In common ┃ Right only ┃
11-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
13-
│ col_a │ ... │ col_d │
14-
│ col_b │ │ │
15-
└────────────┴────────────┴────────────┘
9+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
10+
┃ Left only ┃ In common ┃ Right only ┃
11+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
13+
│ col_a [Null] │ ... │ col_d [Null] │
14+
│ col_b [Null] │ │ │
15+
└──────────────┴──────────────┴──────────────┘
1616

1717
Rows
1818
▔▔▔▔

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_False_slim_True_sample_rows_False_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
Schemas
55
▔▔▔▔▔▔▔
6-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
7-
┃ Left only ┃ In common ┃ Right only ┃
8-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
10-
│ col_a │ ... │ col_d │
11-
│ col_b │ │ │
12-
└────────────┴────────────┴────────────┘
6+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
7+
┃ Left only ┃ In common ┃ Right only ┃
8+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
10+
│ col_a [Null] │ ... │ col_d [Null] │
11+
│ col_b [Null] │ │ │
12+
└──────────────┴──────────────┴──────────────┘

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_False_slim_True_sample_rows_True_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
Schemas
55
▔▔▔▔▔▔▔
6-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
7-
┃ Left only ┃ In common ┃ Right only ┃
8-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
10-
│ col_a │ ... │ col_d │
11-
│ col_b │ │ │
12-
└────────────┴────────────┴────────────┘
6+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
7+
┃ Left only ┃ In common ┃ Right only ┃
8+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
10+
│ col_a [Null] │ ... │ col_d [Null] │
11+
│ col_b [Null] │ │ │
12+
└──────────────┴──────────────┴──────────────┘

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_True_slim_False_sample_rows_False_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
Schemas
88
▔▔▔▔▔▔▔
9-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
10-
┃ Left only ┃ In common ┃ Right only ┃
11-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
13-
│ col_a │ ... │ col_d │
14-
│ col_b │ │ │
15-
└────────────┴────────────┴────────────┘
9+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
10+
┃ Left only ┃ In common ┃ Right only ┃
11+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
13+
│ col_a [Null] │ ... │ col_d [Null] │
14+
│ col_b [Null] │ │ │
15+
└──────────────┴──────────────┴──────────────┘
1616

1717
Rows
1818
▔▔▔▔

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_True_slim_False_sample_rows_True_sample_pk_True.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
Schemas
88
▔▔▔▔▔▔▔
9-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
10-
┃ Left only ┃ In common ┃ Right only ┃
11-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
13-
│ col_a │ ... │ col_d │
14-
│ col_b │ │ │
15-
└────────────┴────────────┴────────────┘
9+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
10+
┃ Left only ┃ In common ┃ Right only ┃
11+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
13+
│ col_a [Null] │ ... │ col_d [Null] │
14+
│ col_b [Null] │ │ │
15+
└──────────────┴──────────────┴──────────────┘
1616

1717
Rows
1818
▔▔▔▔

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_True_slim_True_sample_rows_False_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
Schemas
55
▔▔▔▔▔▔▔
6-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
7-
┃ Left only ┃ In common ┃ Right only ┃
8-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
10-
│ col_a │ ... │ col_d │
11-
│ col_b │ │ │
12-
└────────────┴────────────┴────────────┘
6+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
7+
┃ Left only ┃ In common ┃ Right only ┃
8+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
10+
│ col_a [Null] │ ... │ col_d [Null] │
11+
│ col_b [Null] │ │ │
12+
└──────────────┴──────────────┴──────────────┘

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_False_top_True_slim_True_sample_rows_True_sample_pk_True.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
Schemas
55
▔▔▔▔▔▔▔
6-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
7-
┃ Left only ┃ In common ┃ Right only ┃
8-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
10-
│ col_a │ ... │ col_d │
11-
│ col_b │ │ │
12-
└────────────┴────────────┴────────────┘
6+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
7+
┃ Left only ┃ In common ┃ Right only ┃
8+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
9+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
10+
│ col_a [Null] │ ... │ col_d [Null] │
11+
│ col_b [Null] │ │ │
12+
└──────────────┴──────────────┴──────────────┘

‎tests/summary/fixtures/added_and_removed_columns/gen/pretty_False_perfect_True_top_False_slim_False_sample_rows_False_sample_pk_False.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
Schemas
88
▔▔▔▔▔▔▔
9-
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┓
10-
┃ Left only ┃ In common ┃ Right only ┃
11-
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12-
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━┩
13-
│ col_a │ ... │ col_d │
14-
│ col_b │ │ │
15-
└────────────┴────────────┴────────────┘
9+
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
10+
┃ Left only ┃ In common ┃ Right only ┃
11+
┃ 2 columns ┃ 1 column ┃ 1 column ┃
12+
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
13+
│ col_a [Null] │ ... │ col_d [Null] │
14+
│ col_b [Null] │ │ │
15+
└──────────────┴──────────────┴──────────────┘
1616

1717
Rows
1818
▔▔▔▔

0 commit comments

Comments
 (0)