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

Property path_name can be made more efficient

lverweijen opened this issue · comments

See

return f"{self.parent.path_name}{self.sep}{self.name}"

The property path_name references sep, but the property sep is itself recursive, so it takes k^2 lookups but only k lookups are needed. Furthermore, it does string addition in a (recursive) loop, but there are better ways to construct strings.

Perhaps change this to:

self.sep.join(reversed(self.ancestors))

or probably even faster:

ancestors = list(self.ancestors)
sep = ancestors[-1]._sep  # No recursion because sep is taken directly from root
return sep.join(reversed(ancestors)

Thanks for this suggestion! This will be implemented in v0.9.5 😄

v0.9.5 is now live, do upgrade bigtree with pip install --upgrade bigtree to get the latest changes.