Skip to content

Commit c921155

Browse files
DorAmramproost
authored andcommitted
CLN: changed .format to f-string in pandas/core/dtypes (pandas-dev#30287)
1 parent 687a43e commit c921155

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pandas/core/dtypes/common.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
193193
TypeError: if the value isn't an int or can't be converted to one.
194194
"""
195195
if not is_scalar(value):
196-
raise TypeError(
197-
"Value needs to be a scalar value, was type {}".format(type(value))
198-
)
196+
raise TypeError(f"Value needs to be a scalar value, was type {type(value)}")
199197
msg = "Wrong type {} for value {}"
200198
try:
201199
new_value = int(value)
@@ -1859,7 +1857,7 @@ def _validate_date_like_dtype(dtype) -> None:
18591857
try:
18601858
typ = np.datetime_data(dtype)[0]
18611859
except ValueError as e:
1862-
raise TypeError("{error}".format(error=e))
1860+
raise TypeError(e)
18631861
if typ != "generic" and typ != "ns":
18641862
raise ValueError(
18651863
f"{repr(dtype.name)} is too specific of a frequency, "
@@ -1900,7 +1898,7 @@ def pandas_dtype(dtype):
19001898
npdtype = np.dtype(dtype)
19011899
except SyntaxError:
19021900
# np.dtype uses `eval` which can raise SyntaxError
1903-
raise TypeError("data type '{}' not understood".format(dtype))
1901+
raise TypeError(f"data type '{dtype}' not understood")
19041902

19051903
# Any invalid dtype (such as pd.Timestamp) should raise an error.
19061904
# np.dtype(invalid_type).kind = 0 for such objects. However, this will
@@ -1912,6 +1910,6 @@ def pandas_dtype(dtype):
19121910
# here and `dtype` is an array
19131911
return npdtype
19141912
elif npdtype.kind == "O":
1915-
raise TypeError("dtype '{}' not understood".format(dtype))
1913+
raise TypeError(f"dtype '{dtype}' not understood")
19161914

19171915
return npdtype

pandas/core/dtypes/dtypes.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def construct_from_string(cls, string: str_type):
749749
raise TypeError("Cannot construct a 'DatetimeTZDtype'")
750750

751751
def __str__(self) -> str_type:
752-
return "datetime64[{unit}, {tz}]".format(unit=self.unit, tz=self.tz)
752+
return f"datetime64[{self.unit}, {self.tz}]"
753753

754754
@property
755755
def name(self) -> str_type:
@@ -890,7 +890,7 @@ def __str__(self) -> str_type:
890890

891891
@property
892892
def name(self) -> str_type:
893-
return "period[{freq}]".format(freq=self.freq.freqstr)
893+
return f"period[{self.freq.freqstr}]"
894894

895895
@property
896896
def na_value(self):
@@ -1054,8 +1054,7 @@ def construct_from_string(cls, string):
10541054
if its not possible
10551055
"""
10561056
if not isinstance(string, str):
1057-
msg = "a string needs to be passed, got type {typ}"
1058-
raise TypeError(msg.format(typ=type(string)))
1057+
raise TypeError(f"a string needs to be passed, got type {type(string)}")
10591058

10601059
if string.lower() == "interval" or cls._match.search(string) is not None:
10611060
return cls(string)
@@ -1075,7 +1074,7 @@ def type(self):
10751074
def __str__(self) -> str_type:
10761075
if self.subtype is None:
10771076
return "interval"
1078-
return "interval[{subtype}]".format(subtype=self.subtype)
1077+
return f"interval[{self.subtype}]"
10791078

10801079
def __hash__(self) -> int:
10811080
# make myself hashable

0 commit comments

Comments
 (0)