From 6ad7006dab2f714c6fe564cdfc02cd156de83805 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Fri, 22 Nov 2019 14:23:26 +0200 Subject: [PATCH] Fixes for @jbrockmendel review V1 --- pandas/_libs/tslibs/c_timestamp.pyx | 12 ++++++------ pandas/_libs/tslibs/parsing.pyx | 4 ++-- pandas/_libs/tslibs/period.pyx | 10 +++++----- pandas/_libs/tslibs/strptime.pyx | 8 ++++---- pandas/_libs/tslibs/timedeltas.pyx | 3 ++- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pandas/_libs/tslibs/c_timestamp.pyx b/pandas/_libs/tslibs/c_timestamp.pyx index 3748a02bffe9da..f97786549a95da 100644 --- a/pandas/_libs/tslibs/c_timestamp.pyx +++ b/pandas/_libs/tslibs/c_timestamp.pyx @@ -54,11 +54,11 @@ class NullFrequencyError(ValueError): def maybe_integer_op_deprecated(obj): # GH#22535 add/sub of integers and int-arrays is deprecated if obj.freq is not None: - warnings.warn(f"Addition/subtraction of integers and integer-arrays " + warnings.warn("Addition/subtraction of integers and integer-arrays " f"to {type(obj).__name__} is deprecated, " - f"will be removed in a future " - f"version. Instead of adding/subtracting `n`, use " - f"`n * self.freq`" + "will be removed in a future " + "version. Instead of adding/subtracting `n`, use " + "`n * self.freq`" , FutureWarning) @@ -369,13 +369,13 @@ cdef class _Timestamp(datetime): @property def _repr_base(self) -> str: - return f'{self._date_repr} {self._time_repr}' + return f"{self._date_repr} {self._time_repr}" @property def _date_repr(self) -> str: # Ideal here would be self.strftime("%Y-%m-%d"), but # the datetime strftime() methods require year >= 1900 - return f'{self.year}-{self.month:02d}-{self.day:02d}' + return f"{self.year}-{self.month:02d}-{self.day:02d}" @property def _time_repr(self) -> str: diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 74de0bbadbcce0..ecf3e35c86d768 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -707,8 +707,8 @@ class _timelex: self.stream = instream elif getattr(instream, 'read', None) is None: raise TypeError( - f'Parser must be a string or character stream, not ' - f'{instream.__class__.__name__}') + 'Parser must be a string or character stream, not ' + f'{type(instream).__name__}') else: self.stream = instream.read() diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index b7ff0e1bb18f55..80db081a4fc52d 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1275,15 +1275,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) @@ -2223,7 +2223,7 @@ cdef class _Period: """ base, mult = get_freq_code(self.freq) formatted = period_format(self.ordinal, base) - value = f"{formatted}" + value = str(formatted) return value def __setstate__(self, state): diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index b9654fa5bf13f0..71e50067610978 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -139,8 +139,8 @@ def array_strptime(object[:] values, object fmt, if is_coerce: iresult[i] = NPY_NAT continue - raise ValueError(f"time data {repr(val)} does not match " - f"format {repr(fmt)} (match)") + raise ValueError(f"time data '{val}' does not match " + f"format '{fmt}' (match)") if len(val) != found.end(): if is_coerce: iresult[i] = NPY_NAT @@ -588,8 +588,8 @@ class TimeRE(dict): else: return '' regex = '|'.join(re.escape(stuff) for stuff in to_convert) - regex = f'(?P<{directive}>{regex}' - return f'{regex})' + regex = f'(?P<{directive}>{regex})' + return regex def pattern(self, format): """ diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 066b86fd004255..8e5b7197498578 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1136,7 +1136,8 @@ cdef class _Timedelta(timedelta): return fmt.format(**comp_dict) def __repr__(self) -> str: - return f"Timedelta('{self._repr_base(format='long')}')" + repr_based = self._repr_base(format='long') + return f"Timedelta('{repr_based}')" def __str__(self) -> str: return self._repr_base(format='long')