Skip to content

replace old formatting syntax in shared_docs and Appender #30941

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

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ def __arrow_array__(self, type=None):
if self.freqstr != type.freq:
raise TypeError(
"Not supported to convert PeriodArray to array with different"
" 'freq' ({0} vs {1})".format(self.freqstr, type.freq)
f" 'freq' ({self.freqstr} vs {type.freq})"
)
else:
raise TypeError(
"Not supported to convert PeriodArray to '{0}' type".format(type)
f"Not supported to convert PeriodArray to '{type}' type"
)

period_type = ArrowPeriodType(self.freqstr)
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,11 @@ def ensure_python_int(value: Union[int, np.integer]) -> int:
"""
if not is_scalar(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)
assert new_value == value
except (TypeError, ValueError, AssertionError):
raise TypeError(msg.format(type(value), value))
raise TypeError(f"Wrong type {type(value)} for value {value}")
return new_value


Expand Down
3 changes: 1 addition & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,11 @@ def __eq__(self, other: Any) -> bool:
return hash(self) == hash(other)

def __repr__(self) -> str_type:
tpl = "CategoricalDtype(categories={data}ordered={ordered})"
if self.categories is None:
data = "None, "
else:
data = self.categories._format_data(name=type(self).__name__)
return tpl.format(data=data, ordered=self.ordered)
return f"CategoricalDtype(categories={data}ordered={self.ordered})"

@staticmethod
def _hash_categories(categories, ordered: Ordered = True) -> int:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,7 @@ def _verbose_repr():
dtype = self.dtypes.iloc[i]
col = pprint_thing(col)

line_no = _put_str(" {num}".format(num=i), space_num)
line_no = _put_str(f" {i}", space_num)
count = ""
if show_counts:
count = counts.iloc[i]
Expand Down Expand Up @@ -3792,7 +3792,7 @@ def _reindex_multi(self, axes, copy, fill_value) -> "DataFrame":
fill_value=fill_value,
)

@Appender(_shared_docs["align"] % _shared_doc_kwargs)
@Appender(_shared_docs["align"].format(**_shared_doc_kwargs))
def align(
self,
other,
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8221,7 +8221,7 @@ def ranker(data):
Parameters
----------
other : DataFrame or Series
join : {'outer', 'inner', 'left', 'right'}, default 'outer'
join : {{'outer', 'inner', 'left', 'right'}}, default 'outer'
axis : allowed axis of the other object, default None
Align on index (0), columns (1), or both (None).
level : int or level name, default None
Expand All @@ -8233,7 +8233,7 @@ def ranker(data):
fill_value : scalar, default np.NaN
Value to use for missing values. Defaults to NaN, but can be any
"compatible" value.
method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None
method : {{'backfill', 'bfill', 'pad', 'ffill', None}}, default None
Method to use for filling holes in reindexed Series:

- pad / ffill: propagate last valid observation forward to next valid.
Expand All @@ -8246,19 +8246,19 @@ def ranker(data):
be partially filled. If method is not specified, this is the
maximum number of entries along the entire axis where NaNs will be
filled. Must be greater than 0 if not None.
fill_axis : %(axes_single_arg)s, default 0
fill_axis : {axes_single_arg}, default 0
Filling axis, method and limit.
broadcast_axis : %(axes_single_arg)s, default None
broadcast_axis : {axes_single_arg}, default None
Broadcast values along this axis, if aligning two objects of
different dimensions.

Returns
-------
(left, right) : (%(klass)s, type of other)
(left, right) : ({klass}, type of other)
Aligned objects.
"""

@Appender(_shared_docs["align"] % _shared_doc_kwargs)
@Appender(_shared_docs["align"].format(**_shared_doc_kwargs))
def align(
self,
other,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,7 @@ def _needs_reindex_multi(self, axes, method, level):
"""
return False

@Appender(generic._shared_docs["align"] % _shared_doc_kwargs)
@Appender(generic._shared_docs["align"].format(**_shared_doc_kwargs))
def align(
self,
other,
Expand Down