Repository navigation
fix(medcat): Keep each name's status and the preferred name in merge_cdb - #680
Merged
Merged
Conversation
…erge_cdb merge_cdb passed one status, that of whichever name of the cdb2 concept the set yielded first, to _add_concept for all of the concept's names, so a name marked N in cdb2 could become P and the reverse, depending on the hash seed. The preferred name of a concept only in cdb2 was also replaced by one of its names or left empty. Add the names grouped by their own status and copy cdb2's preferred name for new concepts.
chenyangsu
requested review from
adam-sutton-1992,
mart-r and
vladd-bit
as code owners
November 26, 2026 13:04
mart-r
approved these changes
Nov 26, 2026
mart-r
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the contribution and the thorough description!
Good catch on this one as well! And good PR!
Thanks.
PS: [Again] We haven't used CDB merge in production too much so we haven't been able to catch this. Thanks again!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
merge_cdbtakes the status of whichever name of a cdb2 concept thenamesset yields first, and passes it to_add_conceptfor all of that concept's names, so the result depends on the hash seed. For a cdb2 concept with namesdiabetes~mellitus(P),diabetes(A) anddm(N), merged into a CDB without it:When cdb1 has the same concept, a P from cdb2 can also overwrite cdb1's N or A on the other names. cdb2's preferred name ("Diabetes mellitus") is lost in every case, because
_add_conceptonly sets one from a P name.The names are now grouped by their own status in cdb2, with one
_add_conceptcall per status, and a concept that is new to the merged CDB takes cdb2'spreferred_name. Names without an entry incdb2.name2infoget 'A', the existing default.Testing: the new
test_merge_cdb_keeps_status_of_each_name(cdb1 empty, and cdb1 holding the same concept) fails on main and passes here.python -m unittest tests.utils.test_cdb_utils: 16 tests OK under PYTHONHASHSEED 1 to 4.ruff check medcat --previewand mypy pass.