CLN: replace %s formatting syntax with .format · Issue #16130 · pandas-dev/pandas (original) (raw)

only showing a small snippet. There are about 1000 separate incidents of this (including .py and .pyx) files.

This is pretty easy to change of course (though its somewhat manual).
It provides a cleaner syntax (include kwargs optionally, which makes it more readable). and guards
against accidently trying to format a list/tuple.

(pandas) bash-3.2$ grep -R '%s' pandas --include '*.pyx'
pandas/_libs/interval.pyx:            raise ValueError("invalid option for 'closed': %s" % closed)
pandas/_libs/interval.pyx:                'unorderable types: %s() %s %s()' %
pandas/_libs/interval.pyx:        return ('%s(%r, %r, closed=%r)' %
pandas/_libs/interval.pyx:        return '%s%s, %s%s' % (start_symbol, left, right, end_symbol)
pandas/_libs/lib.pyx:        return '%s(%r)' % (self.__class__.__name__, v)
pandas/_libs/period.pyx:            return '%s/%s' % (period_format(left, 6000),
pandas/_libs/period.pyx:        return "Period('%s', '%s')" % (formatted, self.freqstr)
pandas/_libs/period.pyx:        value = ("%s" % formatted)
pandas/_libs/period.pyx:                        "Invalid frequency or could not infer: %s" % reso)
pandas/_libs/src/properties.pyx:            raise Exception("cannot set values for [%s]" % self.name)

So replacing [5] with [6] or [7]

In [4]: cool = 'cool'

In [5]: "foo is %s" % cool
Out[5]: 'foo is cool'

In [6]: "foo is {}".format(cool)
Out[6]: 'foo is cool'

In [7]: "foo is {cool}".format(cool=cool)
Out[7]: 'foo is cool'

Ideally we would even use f-strings, but only >= 3.6 :<