Make the representation of an object (mainly numbers) more human friendly

    >>> friendly(1e6)
    '1M'
    >>> friendly(-1e3)
    '-1k'
    >>> friendly(1.23456789e9)
    '1.23G'
    >>> friendly(0)
    '0'
    >>> friendly('whatever')
    'whatever'

def friendly(obj):
    """Make the representation of an object (mainly numbers) more human friendly

    >>> friendly(1e6)
    '1M'
    >>> friendly(-1e3)
    '-1k'
    >>> friendly(1.23456789e9)
    '1.23G'
    >>> friendly(0)
    '0'
    >>> friendly('whatever')
    'whatever'
    """
    powers = 'TGMk munp'
    if isinstance(obj, (float, int, long)):
        sign = 1 - 2 * int(obj < 0)
        obj = abs(obj)
        i = 0
        mid = 4
        while np.inf > safe_log(obj, 1000) >= .9999999 and i <= mid and obj > 0 and np.isfinite(obj):
            obj = obj * .001
            i += 1
        while np.inf > safe_log(obj, 1000) < -.25 and i > mid - len(powers) and obj > 0 and np.isfinite(obj):
            obj = obj * 1000.
            i -= 1
        return '{:.3g}{}'.format(sign * obj, powers[mid - i] if i else '')
    return stringify(obj)