code: def calls_sorted(self):
          
          def _z(call):
              if isinstance(call.z.value, np.ndarray):
                  return np.mean(call.z.value.flatten())
              elif isinstance(call.z.value, float) or isinstance(call.z.value, int):
                  return call.z.value
              else:
                  # put it at the back
                  return -np.inf
  
          calls = self._calls
          zs = np.array([_z(c) for c in calls])
          sorted_inds = zs.argsort()
          # TODO: ugh, this is ugly.  Test to find the optimal way to sort
          # while still ending up with a list
          return _call.make_callgroup(np.array(calls)[sorted_inds].tolist())
docs: calls sorted in z