-
Greetings! I am using Python 3.11 with bigtree version 0.17.2. I am trying to create a tree from my data that looks like the below dictionary: data = {
"organization": {
"id": "1234",
"name": "Jack",
"role": "Lead",
"children": [
{
"id": "5678",
"name": "Jack",
"role": "Developer"
}
]
}
} In the data, there is a 'name' key in each node but its values are not unique, hence I need to use 'id' as the key to identify the tree nodes. When I use the below function to create the tree: org_root = nested_dict_to_tree(data["organization"], name_key="id") the operation fails and I get the error messages:
This happens when both, 'id' and 'name' keys are present together. However, if I change 'name' to 'nam' or 'name2', there is no problem and the tree is created successfully. Am I doing something wrong? Or is this a bug? Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, this is intended as In your case, if the unique key is |
Beta Was this translation helpful? Give feedback.
Hello, this is intended as
name
is a special keyword when creatingNode
object. This prevents havingname
as a keyword/identifier, and havingname
again as an attribute.In your case, if the unique key is
id
, when performingnested_dict_to_tree
operation, the name of the Node reads fromid
under the hood, which clashes with thename
attribute that you have. Happy to consider how else to handle this better because of the special keyword constraint fromNode
itself.