kayjan / bigtree

Tree Implementation and Methods for Python, integrated with list, dictionary, pandas and polars DataFrame.

Home Page:https://bigtree.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add a new intermediate node and change the names of the existing nodes to keep the naming consistent?

RomStriker opened this issue · comments

Hi,

I have a tree as follows.

a
├── b
│   └── c
└── d

I want to add a new node c between b and c, and I also want to change the name of c to d and d to e, for the sake of name consistency. So the resulting tree should look like

a
├── b
│   └── c
│       └── d
└── e

Adding a new node was straight forward by just replacing the parent node of c and the new node c, however, I am having trouble changing the name. Is it possible to do this?

Hello, if it is just renaming you can find the node and do a node.name = "e".

An alternative is to call shift_nodes(tree, from_paths=["a/d"], to_paths=["a/e/d"], merge_children=True) which will perform a shifting operation instead of a renaming operation.