From 476b9faea285447c34b00f0c4a934c4b5751b5f8 Mon Sep 17 00:00:00 2001 From: Behemkot Date: Fri, 6 Dec 2019 12:14:44 +0100 Subject: [PATCH 1/3] %s changed to fstring, single quotes in f string changed to double quotes --- pandas/_libs/tslibs/period.pyx | 27 +++++++++++++-------------- pandas/_libs/tslibs/strptime.pyx | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index a6503c00a41bb..0b3b6432c1aea 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1209,8 +1209,7 @@ def period_format(int64_t value, int freq, object fmt=None): elif freq_group == 4000: # WK left = period_asfreq(value, freq, 6000, 0) right = period_asfreq(value, freq, 6000, 1) - return '%s/%s' % (period_format(left, 6000), - period_format(right, 6000)) + return f"(period_format(left, 6000)/period_format(right, 6000))" elif (freq_group == 5000 # BUS or freq_group == 6000): # DAY fmt = b'%Y-%m-%d' @@ -1227,7 +1226,7 @@ def period_format(int64_t value, int freq, object fmt=None): elif freq_group == 12000: # NANOSEC fmt = b'%Y-%m-%d %H:%M:%S.%n' else: - raise ValueError(f'Unknown freq: {freq}') + raise ValueError(f"Unknown freq: {freq}") return _period_strftime(value, freq, fmt) @@ -1275,15 +1274,15 @@ cdef object _period_strftime(int64_t value, int freq, object fmt): if i == 0: repl = str(quarter) elif i == 1: # %f, 2-digit year - repl = f'{(year % 100):02d}' + repl = f"{(year % 100):02d}" elif i == 2: repl = str(year) elif i == 3: - repl = f'{(value % 1_000):03d}' + repl = f"{(value % 1_000):03d}" elif i == 4: - repl = f'{(value % 1_000_000):06d}' + repl = f"{(value % 1_000_000):06d}" elif i == 5: - repl = f'{(value % 1_000_000_000):09d}' + repl = f"{(value % 1_000_000_000):09d}" result = result.replace(str_extra_fmts[i], repl) @@ -1391,7 +1390,7 @@ def get_period_field_arr(int code, int64_t[:] arr, int freq): func = _get_accessor_func(code) if func is NULL: - raise ValueError(f'Unrecognized period code: {code}') + raise ValueError(f"Unrecognized period code: {code}") sz = len(arr) out = np.empty(sz, dtype=np.int64) @@ -1578,8 +1577,8 @@ cdef class _Period: freq = to_offset(freq) if freq.n <= 0: - raise ValueError(f'Frequency must be positive, because it ' - f'represents span: {freq.freqstr}') + raise ValueError(f"Frequency must be positive, because it " + f"represents span: {freq.freqstr}") return freq @@ -1613,8 +1612,8 @@ cdef class _Period: return NotImplemented elif op == Py_NE: return NotImplemented - raise TypeError(f'Cannot compare type {type(self).__name__} ' - f'with type {type(other).__name__}') + raise TypeError(f"Cannot compare type {type(self).__name__} " + f"with type {type(other).__name__}") def __hash__(self): return hash((self.ordinal, self.freqstr)) @@ -1632,8 +1631,8 @@ cdef class _Period: if nanos % offset_nanos == 0: ordinal = self.ordinal + (nanos // offset_nanos) return Period(ordinal=ordinal, freq=self.freq) - raise IncompatibleFrequency(f'Input cannot be converted to ' - f'Period(freq={self.freqstr})') + raise IncompatibleFrequency(f"Input cannot be converted to " + f"Period(freq={self.freqstr})") elif util.is_offset_object(other): freqstr = other.rule_code base = get_base_alias(freqstr) diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index fda508e51e48f..742403883f7dd 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -588,7 +588,7 @@ class TimeRE(dict): else: return '' regex = '|'.join(re.escape(stuff) for stuff in to_convert) - regex = f'(?P<{directive}>{regex})' + regex = f"(?P<{directive}>{regex})" return regex def pattern(self, format): From 803e7ca9b08b3b8cf824318695e847e97d0906a2 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 20 Dec 2019 19:23:22 -0800 Subject: [PATCH 2/3] fixup formatting typo --- pandas/_libs/tslibs/period.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 0b3b6432c1aea..8b62e68d0c1e1 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1209,7 +1209,7 @@ def period_format(int64_t value, int freq, object fmt=None): elif freq_group == 4000: # WK left = period_asfreq(value, freq, 6000, 0) right = period_asfreq(value, freq, 6000, 1) - return f"(period_format(left, 6000)/period_format(right, 6000))" + return f"{period_format(left, 6000)}/{period_format(right, 6000)}" elif (freq_group == 5000 # BUS or freq_group == 6000): # DAY fmt = b'%Y-%m-%d' From a0261390420dc8124a5bcc8c27274e190562a3dc Mon Sep 17 00:00:00 2001 From: William Ayd Date: Tue, 24 Dec 2019 15:08:40 -0500 Subject: [PATCH 3/3] Update period.pyx --- pandas/_libs/tslibs/period.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 8b62e68d0c1e1..ca1d096e75c12 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1577,7 +1577,7 @@ cdef class _Period: freq = to_offset(freq) if freq.n <= 0: - raise ValueError(f"Frequency must be positive, because it " + raise ValueError("Frequency must be positive, because it " f"represents span: {freq.freqstr}") return freq @@ -1631,7 +1631,7 @@ cdef class _Period: if nanos % offset_nanos == 0: ordinal = self.ordinal + (nanos // offset_nanos) return Period(ordinal=ordinal, freq=self.freq) - raise IncompatibleFrequency(f"Input cannot be converted to " + raise IncompatibleFrequency("Input cannot be converted to " f"Period(freq={self.freqstr})") elif util.is_offset_object(other): freqstr = other.rule_code