PERF: optimize get_dtypes, drop unused code