calculate tree height (arbitrary tree) - python
Standard indentation is four spaces.
Missing spaces here and there.
Unnecessary parentheses after while.
Can't handle empty trees.
Name di is really unclear, i and p could also be better.
Using .keys() like that is pointless.
Using negative values is pointless and confusing. Using abs on the result is particularly confusing, as it suggests that the value you give it could be negative or positive. Since you know it's negative, that should've been just -max_distance.
No need to reinvent max.

Rewritten accordingly:
def height(array):
    depth = {-1: 0}
    while len(depth) &lt;= len(array):
        for child, parent in enumerate(array):
            if parent in depth:
                depth[child] = depth[parent] + 1
    return max(depth.values())

For performance, instead of repeatedly searching for children with finished parents, first do one pass to collect each parent's children. Then when you finish a parent, simply go through its previously collected children to finish them, too. This is then linear instead of quadratic time.
Or if the limits are small enough (so far you still haven't answered the comment asking about that), you could use a simple recursive depth(node) function decorated with functools.cache, apply it to all nodes, and take the max. Also linear time.