fix
added test
check target
Showing 4 of 4 files from the diff.
deeplake/util/class_label.py
changed.
deeplake/core/tensor.py
changed.
deeplake/util/merge.py
changed.
@@ -58,12 +58,12 @@
Loading
58 | 58 | return hashes |
|
59 | 59 | ||
60 | 60 | ||
61 | - | def convert_to_text(inp, class_names: List[str]): |
|
61 | + | def convert_to_text(inp, class_names: List[str], return_original=False): |
|
62 | 62 | if isinstance(inp, np.integer): |
|
63 | 63 | idx = int(inp) |
|
64 | 64 | if idx < len(class_names): |
|
65 | 65 | return class_names[idx] |
|
66 | - | return None |
|
66 | + | return idx if return_original else None |
|
67 | 67 | return [convert_to_text(item, class_names) for item in inp] |
|
68 | 68 | ||
69 | 69 |
@@ -878,7 +878,7 @@
Loading
878 | 878 | data = {"value": labels} |
|
879 | 879 | class_names = self.info.class_names |
|
880 | 880 | if class_names: |
|
881 | - | data["text"] = convert_to_text(labels, self.info.class_names) |
|
881 | + | data["text"] = convert_to_text(labels, class_names) |
|
882 | 882 | return data |
|
883 | 883 | if htype in ("image", "image.rgb", "image.gray", "dicom"): |
|
884 | 884 | return { |
@@ -2,6 +2,7 @@
Loading
2 | 2 | from typing import Dict, List, Optional, Set, Tuple |
|
3 | 3 | from deeplake.core.version_control.commit_diff import CommitDiff |
|
4 | 4 | from deeplake.core.version_control.commit_node import CommitNode |
|
5 | + | from deeplake.util.class_label import convert_to_text |
|
5 | 6 | from deeplake.util.diff import ( |
|
6 | 7 | get_lowest_common_ancestor, |
|
7 | 8 | has_change, |
@@ -461,19 +462,21 @@
Loading
461 | 462 | ||
462 | 463 | new_indexes = new_samples_dict[tensor_name] |
|
463 | 464 | new_indexes.sort() |
|
464 | - | is_class_label = original_tensor.meta.htype == "class_label" |
|
465 | + | is_class_label = target_tensor.meta.htype == "class_label" |
|
466 | + | if is_class_label: |
|
467 | + | class_names = target_tensor.info.class_names |
|
465 | 468 | for index in new_indexes: |
|
466 | 469 | sample = target_tensor[index] |
|
467 | - | if is_class_label: |
|
468 | - | sample = sample.data()["text"] |
|
470 | + | if is_class_label and class_names: |
|
471 | + | sample = convert_to_text(sample.numpy(), class_names, return_original=True) |
|
469 | 472 | original_tensor.append(sample) |
|
470 | 473 | original_id_tensor[-1] = target_id_tensor[index] |
|
471 | 474 | ||
472 | 475 | updated_indexes = updated_samples_dict[tensor_name] |
|
473 | 476 | for original_idx, target_idx in updated_indexes: |
|
474 | 477 | sample = target_tensor[target_idx] |
|
475 | - | if is_class_label: |
|
476 | - | sample = sample.data()["text"] |
|
478 | + | if is_class_label and class_names: |
|
479 | + | sample = convert_to_text(sample.numpy(), class_names, return_original=True) |
|
477 | 480 | original_tensor[original_idx] = sample |
|
478 | 481 | ||
479 | 482 |
@@ -430,3 +430,23 @@
Loading
430 | 430 | "g", |
|
431 | 431 | "h", |
|
432 | 432 | } |
|
433 | + | ||
434 | + | ||
435 | + | def test_merge_class_labels_no_classnames(local_ds): |
|
436 | + | with local_ds as ds: |
|
437 | + | ds.create_tensor("labels", "class_label") |
|
438 | + | ds.labels.extend([0, 1, 2, 3]) |
|
439 | + | ds.commit() |
|
440 | + | ||
441 | + | ds.checkout("alt", create=True) |
|
442 | + | ds.labels.extend([4, 5, 0]) |
|
443 | + | ds.commit() |
|
444 | + | ||
445 | + | ds.checkout("main") |
|
446 | + | ds.labels.extend([6, 5, 7]) |
|
447 | + | ds.merge("alt") |
|
448 | + | ||
449 | + | np.testing.assert_array_equal( |
|
450 | + | np.array(ds.labels.numpy()).squeeze(), |
|
451 | + | [0, 1, 2, 3, 6, 5, 7, 4, 5, 0], |
|
452 | + | ) |
Files | Coverage |
---|---|
deeplake | 89.77% |
conftest.py | 100.00% |
setup.py | 0.00% |
Project Totals (253 files) | 89.66% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.