Parameter `attr_omit_null` in root.show and print_tree does not work as expected.
kevint324 opened this issue · comments
Describe the issue
A clear and concise description of what the bug is.
Here says when attr_omit_null is set,
it is Able to omit showing of attributes if it is null, using attr_omit_null
.
Nan value is printed despite of the value of attr_omit_null
Environment
Describe your environment.
- Platform: [Ubuntu]
- Python version: 3.10.12
bigtree
version:0.16.2
To Reproduce
from bigtree import dict_to_tree
from bigtree import Node, print_tree
path_dict4 = {
"root/moduleA": {},
"root/moduleA/Package": {},
"root/moduleA/Package/AAA": {
"url" : "http://google.com"
},
"root/moduleB": {},
"root/moduleB/Package": {
"url" : "www.bing.com"
},
}
root = dict_to_tree(path_dict4)
root.show(attr_list=["url"], attr_omit_null=False)
root.show(attr_list=["url"], attr_omit_null=True)
print_tree(root, attr_list=["url"], attr_omit_null=True)
Expected behaviour
A clear and concise description of what you expected to happen.
The actual output always contains url=nan
.
Should this be omitted when "attr_omit_null" is set?
root
├── moduleA [url=nan]
│ └── Package [url=nan]
│ └── AAA [url=http://google.com]
└── moduleB [url=nan]
└── Package [url=www.bing.com]
root
├── moduleA [url=nan]
│ └── Package [url=nan]
│ └── AAA [url=http://google.com]
└── moduleB [url=nan]
└── Package [url=www.bing.com]
root
├── moduleA [url=nan]
│ └── Package [url=nan]
│ └── AAA [url=http://google.com]
└── moduleB [url=nan]
└── Package [url=www.bing.com]
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Hi, yes you are right thanks for pointing this out. attr_omit_null
checks for None cases but not np.nan. I have implemented a fix in v0.16.3
, do perform pip install --upgrade bigtree
and it should work now!
This project is great and you are awesome!
Thanks!
Hi @kayjan ,
The latest version doesn't work.
Seems the nan checker is too sensitive.
root
├── moduleA
│ └── Package
│ └── AAA [url=http://google.com]
└── moduleB
└── Package [url=www.bing.com]
root
├── moduleA
│ └── Package
Traceback (most recent call last):
File "/home/thw/Downloads/00000camb-arch/test.py", line 18, in <module>
root.show(attr_list=["url"], attr_omit_null=True)
File "/home/thw/.local/lib/python3.10/site-packages/bigtree/node/node.py", line 216, in show
print_tree(self, **kwargs)
File "/home/thw/.local/lib/python3.10/site-packages/bigtree/tree/export.py", line 210, in print_tree
attr_str_list = [
File "/home/thw/.local/lib/python3.10/site-packages/bigtree/tree/export.py", line 213, in <listcomp>
if not _isnull(_node.get_attr(attr_name))
File "/home/thw/.local/lib/python3.10/site-packages/bigtree/tree/export.py", line 63, in _isnull
if not value or math.isnan(value):
TypeError: must be real number, not str
Thanks
It works after a minor fix.
#218
Left a comment on your PR, thanks for testing this change! Sorry for the oversight, I have implemented the fix (again) in v0.16.4, do perform pip install --upgrade bigtree
and it should work now!
It works great. Thanks. Have a nice day.