Skip to content

Commit 9ea8b34

Browse files
committed
CLN: changed .format to f-string in pandas/core/dtypes
1 parent 37dfcc1 commit 9ea8b34

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

pandas/core/dtypes/common.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
194194
"""
195195
if not is_scalar(value):
196196
raise TypeError(
197-
"Value needs to be a scalar value, was type {}".format(type(value))
197+
f"Value needs to be a scalar value, was type {type(value)}"
198198
)
199199
msg = "Wrong type {} for value {}"
200200
try:
@@ -1859,7 +1859,9 @@ def _validate_date_like_dtype(dtype) -> None:
18591859
try:
18601860
typ = np.datetime_data(dtype)[0]
18611861
except ValueError as e:
1862-
raise TypeError("{error}".format(error=e))
1862+
raise TypeError(
1863+
f"{e}"
1864+
)
18631865
if typ != "generic" and typ != "ns":
18641866
raise ValueError(
18651867
f"{repr(dtype.name)} is too specific of a frequency, "
@@ -1900,7 +1902,9 @@ def pandas_dtype(dtype):
19001902
npdtype = np.dtype(dtype)
19011903
except SyntaxError:
19021904
# np.dtype uses `eval` which can raise SyntaxError
1903-
raise TypeError("data type '{}' not understood".format(dtype))
1905+
raise TypeError(
1906+
f"data type '{dtype}' not understood"
1907+
)
19041908

19051909
# Any invalid dtype (such as pd.Timestamp) should raise an error.
19061910
# np.dtype(invalid_type).kind = 0 for such objects. However, this will
@@ -1912,6 +1916,8 @@ def pandas_dtype(dtype):
19121916
# here and `dtype` is an array
19131917
return npdtype
19141918
elif npdtype.kind == "O":
1915-
raise TypeError("dtype '{}' not understood".format(dtype))
1919+
raise TypeError(
1920+
f"dtype '{dtype}' not understood"
1921+
)
19161922

19171923
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)