def _tz_localize(ax, tz, ambiguous, nonexistent):
    if (not hasattr(ax, 'tz_localize')):
        if (len(ax) > 0):
            ax_name = self._get_axis_name(axis)
            raise TypeError(('%s is not a valid DatetimeIndex or PeriodIndex' % ax_name))
        else:
            ax = DatetimeIndex([], tz=tz)
    else:
        ax = ax.tz_localize(tz, ambiguous=ambiguous, nonexistent=nonexistent)
    return ax
def _tz_localize(ax, tz, ambiguous, nonexistent):
    if (not hasattr(ax, 'tz_localize')):
        if (len(ax) > 0):
            ax_name = self._get_axis_name(axis)
            raise TypeError(('%s is not a valid DatetimeIndex or PeriodIndex' % ax_name))
        else:
            ax = DatetimeIndex([], tz=tz)
    else:
        ax = ax.tz_localize(tz, ambiguous=ambiguous, nonexistent=nonexistent)
    return ax