def pandas_dtype(dtype):
 if isinstance(dtype, DatetimeTZDtype):
  return dtype
 elif isinstance(dtype, PeriodDtype):
  return dtype
 elif isinstance(dtype, CategoricalDtype):
  return dtype
 elif isinstance(dtype, string_types):
  try:
   return DatetimeTZDtype.construct_from_string(dtype)
  except TypeError:
   pass
  if (dtype.startswith('period[') or dtype.startswith('Period[')):
   try:
    return PeriodDtype.construct_from_string(dtype)
   except TypeError:
    pass
  try:
   return CategoricalDtype.construct_from_string(dtype)
  except TypeError:
   pass
 elif isinstance(dtype, ExtensionDtype):
  return dtype
 return np.dtype(dtype)

def pandas_dtype ( dtype ) : if isinstance ( dtype , DatetimeTZDtype ) : return dtype elif isinstance ( dtype , PeriodDtype ) : return dtype elif isinstance ( dtype , CategoricalDtype ) : return dtype elif isinstance ( dtype , string_types ) : try : return DatetimeTZDtype . construct_from_string ( dtype ) except TypeError : pass if ( dtype . startswith ( 'period[' ) or dtype . startswith ( 'Period[' ) ) : try : return PeriodDtype . construct_from_string ( dtype ) except TypeError : pass try : return CategoricalDtype . construct_from_string ( dtype ) except TypeError : pass elif isinstance ( dtype , ExtensionDtype ) : return dtype return np . dtype ( dtype )
converts input into a pandas only dtype object or a numpy dtype object .