diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 602d7d0da95e6..8e629896fdb7b 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -193,9 +193,7 @@ def ensure_python_int(value: Union[int, np.integer]) -> int: TypeError: if the value isn't an int or can't be converted to one. """ if not is_scalar(value): - raise TypeError( - "Value needs to be a scalar value, was type {}".format(type(value)) - ) + raise TypeError(f"Value needs to be a scalar value, was type {type(value)}") msg = "Wrong type {} for value {}" try: new_value = int(value) @@ -1859,7 +1857,7 @@ def _validate_date_like_dtype(dtype) -> None: try: typ = np.datetime_data(dtype)[0] except ValueError as e: - raise TypeError("{error}".format(error=e)) + raise TypeError(e) if typ != "generic" and typ != "ns": raise ValueError( f"{repr(dtype.name)} is too specific of a frequency, " @@ -1900,7 +1898,7 @@ def pandas_dtype(dtype): npdtype = np.dtype(dtype) except SyntaxError: # np.dtype uses `eval` which can raise SyntaxError - raise TypeError("data type '{}' not understood".format(dtype)) + raise TypeError(f"data type '{dtype}' not understood") # Any invalid dtype (such as pd.Timestamp) should raise an error. # np.dtype(invalid_type).kind = 0 for such objects. However, this will @@ -1912,6 +1910,6 @@ def pandas_dtype(dtype): # here and `dtype` is an array return npdtype elif npdtype.kind == "O": - raise TypeError("dtype '{}' not understood".format(dtype)) + raise TypeError(f"dtype '{dtype}' not understood") return npdtype diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 77ec182be5ed4..6f8f6e8abbc0a 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -749,7 +749,7 @@ def construct_from_string(cls, string: str_type): raise TypeError("Cannot construct a 'DatetimeTZDtype'") def __str__(self) -> str_type: - return "datetime64[{unit}, {tz}]".format(unit=self.unit, tz=self.tz) + return f"datetime64[{self.unit}, {self.tz}]" @property def name(self) -> str_type: @@ -890,7 +890,7 @@ def __str__(self) -> str_type: @property def name(self) -> str_type: - return "period[{freq}]".format(freq=self.freq.freqstr) + return f"period[{self.freq.freqstr}]" @property def na_value(self): @@ -1054,8 +1054,7 @@ def construct_from_string(cls, string): if its not possible """ if not isinstance(string, str): - msg = "a string needs to be passed, got type {typ}" - raise TypeError(msg.format(typ=type(string))) + raise TypeError(f"a string needs to be passed, got type {type(string)}") if string.lower() == "interval" or cls._match.search(string) is not None: return cls(string) @@ -1075,7 +1074,7 @@ def type(self): def __str__(self) -> str_type: if self.subtype is None: return "interval" - return "interval[{subtype}]".format(subtype=self.subtype) + return f"interval[{self.subtype}]" def __hash__(self) -> int: # make myself hashable