-
Notifications
You must be signed in to change notification settings - Fork 52
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
Strange Behavior with Copy #1400
Comments
Hi @yoavkatz , it is not odd, it is as planned.. Pending the flag from unitxt.dict_utils import dict_set
dic = {"source": "hello", "task_data" :3}
try:
dict_set(dic, "task_data/source", "hello", not_exist_ok=False)
print(dic)
except Exception as e:
print(e) # prints No path in dic {'source': 'hello', 'task_data': 3} matches query task_data/source
dic = {"source": "hello", "task_data" :3}
try:
dict_set(dic, "task_data/source", "hello", not_exist_ok=True)
print(dic) # prints {'source': 'hello', 'task_data': {'source': 'hello'}}
except Exception as e:
print(e) |
Here is how dict_set(
instance,
to_field,
new_value,
not_exist_ok=True, # << note here
) We may want to change it to use the flag |
Thanks for the explanation. I think the most natural behavior, which does not require additional flags, is that if that you can always assign to a non exist field, but only at the last level. Assume: { "source": "my string", "task_data" : {"format" : "my string", "options" : ["a","b","c"] } The we can assign to a "new_field", or to "source" or to "task_data", or to "task_data/format", or to "task_data/options" or to "task_data/options/0". But we can not assign to "source/0" or "task_data/format/a". Building such implicit data structures is non expected (we also don't know if we need to build a dictionary or a list when assigning to non existent field : a/0/field". |
Thanks, @yoavkatz , thats a neat idea. It also solves the problem I started to cook around (silently for now.. :-)): what to do with 0 like in your example, a 0 that can be both an index into a list but also a field name, as used in rendered-to-json tables, for example. I was cooking around the already currently existing flag of A question: It is still OK to replace any existing value, of any complexity, and sitting in a field of any depth in dic, by a new value, of any complexity too. Right? E.g., In your example above, it is OK to assign a new value, of any complexity (dict of lists of dicts, or just a simple str) to I will push a PR soon. |
@yoavkatz , I see some points in existing code where {
"__type__": "copy",
"field_to_field": {
"task_data/reference_answers": "references"
}
} What if at this stage the instance does not have a field named |
Hi. I think on this case task_data/reference_answer is the source. If it does not exist , it should fail. If the target reference field does not exist, it should be created (that's fube because it's not nested). |
Ahh, yes, my mistake. In my example the nested field is the source, not the target. Sorry. |
Hi @yoavkatz ,
I will change it here to a two step operation, but there might be other places like this in users' code.. |
If we copy a string to a nested field in another string field (which is meaningless) , we get this odd behavior that the target string field becomes a dictionary, with the copied value.
The text was updated successfully, but these errors were encountered: