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

Attribute values

virsto opened this issue · comments

You have some nice examples for defining a tree structure in your code. However, your code does not allow certain attribute values. The examples in your code use age where ages can be positive are negative(?) but do not allow a value of 0 -- Why? Suppose I wished to have an attribute at each node that represents the number of bytes for each node, e.g. Node("c",bytes=0,parent=root). When a node has 0 bytes your code will display the name of the node but not the value of 0. And why are integer values of ages converted to float values?

In general, I am very impressed by your bigtree package -- I use it quite often for zipping complex directories and encryption/decryption. Keep up the good work :-)

There isn't any restrictions on the attribute values or data type conversions - can you provide examples where you cannot set the age attribute as 0 and when the integer value attributes get converted to float values?

By default, null or zero values of attributes are omitted from printing, but you can set attr_omit_null=False to show the attributes when byte=0. For example,

from bigtree import Node, print_tree

# Construct tree
root = Node("a", byte=1)
b = Node("b", byte=0, parent=root)
c = Node("c", byte=1, parent=root)
d = Node("d", byte=-1, parent=b)

print_tree(root, attr_list=["byte"], attr_omit_null=False)

This will result in the output

a [byte=1]
├── b [byte=0]
│   └── d [byte=-1]
└── c [byte=1]

Hope this helps!