CLN, TYP: Factor out part of info
Precursor to #31796, which still has a rather large diff. This should help make it easier to read.

On master, `cols` holds the DataFrame's columns. If we were to use this method on a Series, then it would hold an Index containing the Series' name (`Index([data.name])`). Is there a good name for a variable that could store either? At the moment I've called it `ids`