Skip to content

CLN: changed .format to f-string in pandas/core/dtypes #30287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, "
Expand Down Expand Up @@ -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
Expand All @@ -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
9 changes: 4 additions & 5 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down