Clean up code duplication in _optional and _print_versions
ref this comment https://github.com/pandas-dev/pandas/pull/26802#discussion_r293045993 we currently duplicate code in managing versions between the pandas.compat._optional and pandas.util._print_versions modules which we should align