Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map annotation enhancement; list of values possible #112

Merged

Conversation

JensWendt
Copy link
Contributor

Description

This tries to implement the option to pass a Key-Value dict containing multiple values for one key which then will create multiple Key-Value pairs in OMERO.
Multiple instances of the key, each with one value.
kv_dict = {"key1": ["value1", "value2"]}
would become in OMERO:

key1 : value1
key1 : value2

The reason for this is, that I needed/wanted it, as the same functionality is also present in the new "KeyValue_from_csv" OMERO.web scripts.
And it doesn't make sense to me, that the python package should have less functionality.

Checklist

It seems to me like I checked everything.
But please double check, as I am not intimately familiar where I have to adapt things everywhere, as not to break things.

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.

Copy link
Collaborator

@erickmartins erickmartins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple comments in there - let me know your thoughts!

for item in map_annotation:
if item[0] in map_annotation_dict:
if not isinstance(map_annotation_dict[item[0]], list):
map_annotation_dict[item[0]] = [map_annotation_dict[item[0]]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this bit might be much simplified by using defaultdicts instead of regular dicts - the downside is that every value from every key-value pair would be a list (of size 1, if there's a single value for that key).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, yes.
that is a smoother way to write this.
I was not aware of this feature.
I would even say it makes more sense to get a list for everything, so you always get the same data-type.
Something like:

map_annotation_dict = defaultdict(list)
for item in map_annotation:
	map_annotation_dict[item[0]].append(item[1])

But I would leave the decision about this up to you, as it is your library.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using defaultdicts and always getting a list might make more sense (and results in a more consistent API). It is a breaking change for the API, so it might take a bit longer to make it to release, but I think it makes future maintenance easier, so we should probably do that.

@@ -166,8 +166,7 @@ def set_or_create_screen(conn: BlitzGateway, screen: Union[str, int],

def multi_post_map_annotation(conn: BlitzGateway, object_type: str,
object_ids: Union[int, List[int]], kv_dict: dict,
ns: str, across_groups: Optional[bool] = True
) -> int:
ns: str) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why across_groups has disappeared here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the parameter was not being used in the function and it did not have the decorator @do_across_groups
I just saw it and removed it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good point! I didn't realize this was an importer function.

@JensWendt
Copy link
Contributor Author

Heyo,
I made the classic rookie mistake of pushing a PR and then going on holiday :)
Just now answered your questions.

@erickmartins
Copy link
Collaborator

ok, with the benefit of a couple more days to think about this, I think I've flipped back to your original implementation. Most of the time there will be a single value per key, and for that more common use case we should stick to the main tenet of ezomero (a simple interface for the Python API), even if that makes maintenance marginally more difficult - so that should return a dict with string values, instead of always returning a list.

Apologies @JensWendt for the extra work and for the flip-flopping :) I've submitted a commit reverting things to your original implementation. Thanks a lot for the PR!

@JensWendt
Copy link
Contributor Author

Okay,
all good. I am happy that we get to implement it in any way.
And with your reversion, it is not really extra work ^^ hurray for git versioning :D
Just to make sure, it is now in a state that is okay for you and ready to merge at some point in the future?
Or is there something else to improve?

@erickmartins
Copy link
Collaborator

Okay, all good. I am happy that we get to implement it in any way. And with your reversion, it is not really extra work ^^ hurray for git versioning :D Just to make sure, it is now in a state that is okay for you and ready to merge at some point in the future? Or is there something else to improve?

We should all be good to go - just gave it a day so you could see this was happening before I merged it :)

@erickmartins erickmartins merged commit 9b0d569 into TheJacksonLaboratory:main Aug 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants