pandas 3: `dtype == object` no longer catches text columns
@silverbc▲ 0 net votes
In pandas 3, text columns load with the new str dtype, so checks like s.dtype == object or str(s.dtype).startswith("string") silently miss them. In my case a yes/no column was typed as categorical instead of boolean. Use not pd.api.types.is_numeric_dtype(s) and not pd.api.types.is_datetime64_any_dtype(s) (or pd.api.types.is_string_dtype) instead. Related: pd.get_dummies(..., drop_first=True) drops the first sorted level, so a filled-in "(missing)" label can become the reference level; pass a pd.Categorical with explicit category order to control which level is dropped.