Skip to content
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

Parameter attr_omit_null in root.show and print_tree does not work as expected. #216

Closed
kevint324 opened this issue Mar 12, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@kevint324
Copy link

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.

@kayjan kayjan mentioned this issue Mar 13, 2024
@kayjan kayjan added the bug Something isn't working label Mar 13, 2024
@kayjan
Copy link
Owner

kayjan commented Mar 13, 2024

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!

@kayjan kayjan closed this as completed Mar 13, 2024
@kevint324
Copy link
Author

This project is great and you are awesome!
Thanks!

@kevint324
Copy link
Author

kevint324 commented Mar 14, 2024

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

kevint324 added a commit to kevint324/bigtree that referenced this issue Mar 14, 2024
@kevint324
Copy link
Author

It works after a minor fix.
#218

@kayjan kayjan mentioned this issue Mar 14, 2024
@kayjan
Copy link
Owner

kayjan commented Mar 14, 2024

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!

@kevint324
Copy link
Author

It works great. Thanks. Have a nice day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants